-- --

Shifting from C to C++ :

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:
          stdio.h

 

  • C++ :
iostream.h

2.     Input Output statements/streams:

  • C:
scanf(" ")

and

printf(" ")

 

  • C++:
cin>>

and

cout<<

(respectively)

3.     No need of mentioning the type of variable while giving input or printing output, it is detected automatically.

  • C:
int integer;
scanf(“%d”,&integer);
printf("%d”,integer);
  • C++:
int integer
cin>>integer;
cout<<integer;

4.     The access specifiers(discussed in detail later):

  • C:

Only public(not mentioned explixitly)

  • C++:

private by default, public/protected (by mentioning explicitly)

5.     It is necessary to provide a return type of a function unlike C.

  • C:
test();

is a valid prototype

  • C++
test();

is INVALID whereas

void type();

is VALID

kaliadevansh has written 15 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>