Tuesday, 28 March 2017

Differences Between C And C++

1. C is a procedural language whereas C++ is a non-procedural language. 

2. C gives importance to functions (methods) whereas C++ gives importance to both functions and data. 

3. C allows the data to flow around the functions freely whereas C++ wraps up the data and functions together due to that datas were not allowed to flow around freely in C++. This is said to be Encapsulation in C++ 

Other differences ( actucally there is lot to mention......here are the two ) 

1. C allows struct union and enum types to be declared in function prototypes whereas C++ does not. 

2. A struct union or enum declaration in C++ declares an implicit typedef while in C it does not 

Example of C program:

main()
{
int a=5,b=6,c;
c=a+b;
printf("Result in C:-");
printf("%d",&c);
getch();


In this program we Add two integer Number and the result save in variable C. Here printf is a function used for display the result.
getch(); function is used to echo the output.


Example of C++ program:

void main()
{
int a=5,b=6,c;
c=a+b;
cout<<"Result in C:-";
cout<<c;
getch();

In c++ for displaying the result we use cout<<  function.

No comments:

Post a Comment