C++ tutorial provides basic and advanced concepts of C++. Our C++ tutorial is designed for beginners and professionals.
C++ is an object-oriented programming language. It is an extension to C programming.
Our C++ tutorial includes all topics of C++ such as first example, control statements, objects and classes, inheritance, constructor, destructor, this, static, polymorphism, abstraction, abstract class, interface, namespace, encapsulation, arrays, strings, exception handling, File IO, etc.
C++ is a general purpose, case-sensitive, free-form programming language that supports object-oriented, procedural and generic programming.
C++ is a middle-level language, as it encapsulates both high and low level language features.
C++ supports the object-oriented programming, the four major pillar of object-oriented programming (OOPs) used in C++ are:
- Inheritence
- Polymorphism
- Encapsulation
- Abstraction
Standard C++ programming is divided into three important parts:
- The core library includes the data types, variables and literals, etc.
- The standard library includes the set of functions manipulating strings, files, etc.
- The Standard Template Library (STL) includes the set of methods manipulating a data structure.
By the help of C++ programming language, we can develop different types of secured and robust applications:
- Window application
- Client-Server application
- Device drivers
- Embedded firmware etc
In this tutorial, all C++ programs are given with C++ compiler so that you can easily change the C++ program code.
File: main.cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello C++ Programming";
return 0;
}
C++ I/O operation is using the stream concept. Stream is the sequence of bytes or flow of data. It makes the performance fast.
If bytes flow from main memory to device like printer, display screen, or a network connection, etc, this is called as output operation .
If bytes flow from device like printer, display screen, or a network connection, etc to main memory, this is called as input operation .
The cout is a predefined object of ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to display the output on a console
Let's see the simple example of standard output stream (cout):
#include <iostream>
using namespace std;
int main() {
char ary[] = "Welcome to C++ tutorial";
cout << "Value of ary is: " << ary << endl;
}
Output:
Value of ary is: Welcome to C++ tutorial
The cin is a predefined object of istream class. It is connected with the standard input device, which is usually a keyboard. The cin is used in conjunction with stream extraction operator (>>) to read the input from a console.
Let's see the simple example of standard input stream (cin):
#include <iostream>
using namespace std;
int main( ) {
int age;
cout << "Enter your age: ";
cin >> age;
cout << "Your age is: " << age << endl;
}
Output:
Enter your age: 22 Your age is: 22
The endl is a predefined object of ostream class. It is used to insert a new line characters and flushes the stream.
Let's see the simple example of standard end line (endl):
#include <iostream>
using namespace std;
int main( ) {
cout << "C++ Tutorial";
cout << " Javatpoint"<< endl;
cout << "End of line"<< endl;
}
Output:
C++ Tutorial Javatpoint End of line
A variable is a name of memory location. It is used to store data. Its value can be changed and it can be reused many times.
It is a way to represent memory location through symbol so that it can be easily identified.
Let's see the syntax to declare a variable:
type variable_list;
The example of declaring variable is given below:
int x;
float y;
char z;
Here, x, y, z are variables and int, float, char are data types.
We can also provide values while declaring the variables as given below:
int x=5,b=10; //declaring 2 variable of integer type
float f=30.8;
char c='A';
All the documentation in this page is taken from JAVATPOINT