The C++ programming language was created by Bjarne Stroustrup and his team at Bell Laboratories (AT&T, USA).C++ reads as C plus plus was derived from C programming language. ++ denotes the increment operator in C meaning increment of C is C++.
C++ greatly influenced development of C# and Java.
Characteristics of C++
C progarm source code can be easily converted to C++ programs. C++ supports concepts for OOP (Object Oriented programming).
1. Data Abstraction
It is the ability to represent data at a very conceptual level without any details.
2. Data Encapsulation
Data Encapsulation means protecting data form outside interfaces and controlling the access to data.
3. Inheritance
It means a class can be derived from base/parent class. The base class will have all the characteristics and feature of parent class.
4. Polymorphism
Polymorphism is the ability to exist in various forms. It means representing same things differently.We will further discuss about above topics in detail in next tutorial.
Advantages of OOP
In traditional concept of programming data and functions are kept separately. Due to which programmer must initialized suitable values before use.
Traditional Concept
fig: traditional concept
OOP Concept
fig: OOP
1. Easy Reuse of code
Objects can be used as the building blocks of other program.
2. Low Maintenance
An object can change its properties: data member, functions without needing to change the application.
3. Ownership of data
An object controls access to its data. So it can reject request of accessing it data outside the object.
How does C++ program works
After writing source code, it is then compiled by compiler which converts the high level language to machine code. Then linker combines the object file to form an executable file.
Any syntax error in program will be reported while compiling and more errors will be shown if further compiling takes place.
fig: working of C++ program
Hello world in C++
#include <iostream.h>
int main()
{
cout << "Hello World";
return (0);
}
To run the above program, We will be using Turbo C++. Download turbo C++ here.
Output
Hello World
In above example,
#include <iostream.h>
Here, the line begins with # i.e the line is intended for processor. iostream.h is the header file. Above line import the iostream.h header file. iostream helps treating information as flow of data.
int main()
It indicates it is the main program. Once the program executes it will look for the main function. Execution of program starts here.
cout << "Hello World";
This outputs the text to Hello World on the screen. COUT means console output. << indicate that characters are being pushed to screen.
return 0;
It terminates the function and program while returning 0 indicating termination of program correctly.