Introduction to C++
Introduction
OOP developed by Bjarne Stroustrup at AT&T Bell laboratories in 1980s Combination of Simula67 and C Classes, inheritance, function overloading, and operator overloading are the most important features in C++
Differences between C and C++ (1)
Keywords asm catch class new operator private protected public using namespace Length of identifiers No limit in C++ Declarations In C global variables can be declared several times without using extern specifier. But in C++, it must be declared once without extern and all the remaining must use the extern specifier Global const In C, a global const has an external linkage. But in C++, all const values are static by default and thus become local
Differences between C and C++ (2)
Main function
In C++ main() function must return a value of type int
Functions with no arguments
Example: int myFunction() This means unspecified number of arguments in C and exactly zero arguments in C++
Inline functions inline int add(int a, int b) { return (a+b); } Default function arguments
Void myFunction(int a, int b=5, int c=10);
Differences between C and C++ (3)
Declarations
In C, all declarations should be made at the top. But in C++, declarations can be made at any point of the program
Scope Resolution
An operator :: known as scope resolution operator is used in C++ to access an item outside the current scope.
Differences between C and C++ (4)
Comments
C++ supports // comment style in addition to /*.*/ comment style Useful for one line comment