Introduction to C++
Introduction
Many of you might have learnt C programming language before and trying to learn new skill i.e. C++. It is well and good. But even if you are totally new to programming and trying to learn C++ directly without any programming background , then also no problem at all. Just follow the entire course patiently and understand every concept thoroughly. Try writing programs on your own and play around it testing many sample cases.
At the end of this course ,you will have strong knowledge of C++ and will be able to write many simple as well as complex programs on your on.
So without wasting much time ,let's get started and throw ourselve in C++ world!
At the end of this course ,you will have strong knowledge of C++ and will be able to write many simple as well as complex programs on your on.
So without wasting much time ,let's get started and throw ourselve in C++ world!
History of C++
C++ was developed by Bjarne stroustrup in early 1980's at AT&T Bell labs, New Jersey ,USA. C++ is an intermediate level programming language. It implements the features of both high level and low level programming languages.
C++ is a Object Oriented Programming language,meaning that C++ has classes and objects and follows almost all the properties of OOP. C++ is extension of C , with classes ,inheritance,polymorphism,function overloading, operator overloading added in extra that makes C++ more usable than C.
C++ is a Object Oriented Programming language,meaning that C++ has classes and objects and follows almost all the properties of OOP. C++ is extension of C , with classes ,inheritance,polymorphism,function overloading, operator overloading added in extra that makes C++ more usable than C.
# First C++ Program ( "Hello World")
Download the code here
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World ! \n";
return 0;
}
using namespace std;
int main()
{
cout<<"Hello World ! \n";
return 0;
}
Note : This code is successfully compiled and run under Linux distribution Ubuntu 18.04 LTS environment .
Output :
Hello World !
Explanation of above program
- #include : It is pre-processor directive meaning that it tells compiler that which library to include during compilation.For example , in above program we told compiler to add iostream (pre-defined input/output library) to be added during compilation.
- iostream : Predefined I/O library used to display the output on screen or take input from keyboard. cout for displaying the output and cin for taking input from keyboard.
- namespace : It include all C++ standard libraries. This is optional line but instead you have to use scope resolution operator( :: ) at every cout or cin statement, like std::cout or std::cin.
- int main : This is the very important function in whole program. The program execution always starts from main function.
- cout<< : cout is an output object already defined in iostream library used to display output on screen. " << " operator is called as extraction operator and always used with cout.
- return 0 : As main function is of type int , it should return something to operating system. This return statement ensures to return integer value to operatinng system.
Some general rules for writing C++ program:
i. Every statement should end with semicolon ( ; ) .
ii.Every function should be enclosed within pair of curly braces {}.
Advantages of C++ over C
- As C++ is object oriented language, use of classes ,inheritance,polymorphism , data encapsulation ,data abstraction makes code size smaller, code re-usability, and easy to maintain.
- Memory management is possible in C++ very efficiently.
- C++ is very efficient for low level programming and efficient for general purpose programming.
- Because C++ is object oriented programming language, it is used in developing real life projects.
- OOP feature in C++ facilitate programmer to build software with clarity,extensibility and ease of maintenance.
0 Comments