C++ Tutorial

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.

What is C++

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.

Object-Oriented Programming (OOPs)

C++ supports the object-oriented programming, the four major pillar of object-oriented programming (OOPs) used in C++ are:

  1. Inheritence
  2. Polymorphism
  3. Encapsulation
  4. Abstraction
C++ Standard Libraries

Standard C++ programming is divided into three important parts:

Usage of C++

By the help of C++ programming language, we can develop different types of secured and robust applications:

C++ Program

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++ Basic Input/Output

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 .

Standard output stream (cout)

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
          
Standard input stream (cin)

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
          
Standard end line (endl)

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
          
C++ Variable

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';   
           
Reference

All the documentation in this page is taken from JAVATPOINT