Differences between C
and C++:
1) When a function takes no parameter, its
prototype has the word void inside parenthesis.
int fun(void);
However, in C++ the void
is optional.
int fun();
If this convention would
use in C, it mean that nothing is said about the parameters.
2) In a C++ program, all functions
must be prototyped. In C, prototypes are recommended but
technically optional.
3) About keyword return:
In C++, if a
function is declared as returning a value, that is return type other than void,
any return statement within that function must contain
a value.
In C, a non void
function is not required to actually return a value. If it doesn’t, a garbage value
is returned.
4) Comments:
In C, comments in
the program can be specified by /*….*/
In C++, due to
backward compatibility, /*….*/ is still used for multiple line
comments. We can also make a single line as comment by prefix that line by //
5) Declaration of local variables:
In C local
variables can be declared only at the start of a block prior
to any action statements.
In C++ local
variables can be declared anywhere in the block.
6) Reference variable
In C++, reference
variable are implicit pointers that acts as another variable name for some
existing variable. There is no concept of reference variable in C.
7) Top Down and Bottom up approach
C programmer
follows top down approach for programming
It is a program design
technique that starts with the highest level of an idea and works its
way down to the lowest level of detail.
C++ programmer
adopts bottom up approach for programming.
In a bottom-up approach
the individual base elements of the system are first specified in great detail.
These elements are then linked together to form larger subsystems, which then
in turn are linked, sometimes in many levels, until a complete top-level system
is formed.
8) Procedure oriented Programming and Object
Oriented Programming
Procedure oriented
Programming:
Main program is divided into small parts depending on the
functions.
The Different part of the program connects with
each other by parameter passing. Most of the functions use global data.
Object Oriented
Programming:
Main program is divided into small objects depending
on the problem.
Data & functions of each individual object
act like a single unit.
Each object controls its own data.
Data hiding is possible in OOP which prevent illegal access of function
from outside of it. This is one of the best advantages of OOP.
No comments:
Post a Comment