C is a procedure oriented language. It follows the Top down approach (i.e. analyzing the problem and dealing with it) whereas C++ is an object-oriented programming language and follows the bottom up approach (i.e. breaking the problem into parts, dealing with those parts and hence solving the problem).
The main focus while programming in C is on functions whereas in C++, it is on classes and objects. Before going deeper into classes, we will make some programs in C++ which are equivalent to those in C.
There are some syntactical differences between C and C++ that one must know to construct a basic C++ program:
1. Input Output library:
- C++ :
2. Input Output statements/streams:
3. No need of mentioning the type of variable while giving input or printing output, it is detected automatically.
int integer; scanf(“%d”,&integer); printf("%d”,integer);
int integer cin>>integer; cout<<integer;
4. The access specifiers(discussed in detail later):
Only public(not mentioned explixitly)
private by default, public/protected (by mentioning explicitly)
5. It is necessary to provide a return type of a function unlike C.
is a valid prototype
is INVALID whereas