Docsity

Difference between C and C++ programming languages, Cheat Sheet of Computer science

Toggle sidebar
bg1
Differences between C and C++
a) When a function takes no parameter, its prototype has the word void inside-parenthesis. Int
fun(void); However, in C++ the void is optional.
If this convention would use in C, it mean that nothing is said about the parameters.
b) In C++ program , all function must be prototyped. In C, prototypes are recommended but
technically optional.
c) About keyword return:
In C++, if a function declared as returning a value, that is return type other then void, any return
statement within that function must be 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.
d) Comments:
In C,comments in 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 comment by prefix that line by //.
e) Declaration of local variables
In C local variable 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.
f) Reference variable
In C++, reference variable are Implicit pointer that acts as another variable name for some existing
variable. There is no concept of reference variable C.
g) Top Down and Bottom approach
C Programmer follow top down approach for programming. It is a program design technique that start
with the highest level of an idea and works its way down to the lowest level of detail.C++ programmer
adopt bottom up approach for programming. In a bottom-up approach the individual base element of
the system are first specified in great detail. These element are then linked together to from larger
subsystem, which then in turn are linked, sometime in many levels, until a complete top-level system
is formed.
h) Producer oriented programming and object oriented programming
Producer oriented programming main program is divided into small parts depending on the function.
The different part of the program connects with each other by parameter passing most of the
function use global data. Object oriented programming main program is divided into small object
depending on the problem. Data & function of each individual object act like a single unit. Each object
control its own data. Data hiding is possible in OOP which prevent illegal access of function from
outside of it. This one of the best advantages of OOP.

Partial preview of the text

Download Difference between C and C++ programming languages and more Cheat Sheet Computer science in PDF only on Docsity!

Differences between C and C++

a) When a function takes no parameter, its prototype has the word void inside-parenthesis. Int fun(void); However, in C++ the void is optional. If this convention would use in C, it mean that nothing is said about the parameters. b) In C++ program , all function must be prototyped. In C, prototypes are recommended but technically optional. c) About keyword return: In C++, if a function declared as returning a value, that is return type other then void, any return statement within that function must be 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. d) Comments: In C,comments in 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 comment by prefix that line by //. e) Declaration of local variables In C local variable 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. f) Reference variable In C++, reference variable are Implicit pointer that acts as another variable name for some existing variable. There is no concept of reference variable C. g) Top Down and Bottom approach C Programmer follow top down approach for programming. It is a program design technique that start with the highest level of an idea and works its way down to the lowest level of detail.C++ programmer adopt bottom up approach for programming. In a bottom-up approach the individual base element of the system are first specified in great detail. These element are then linked together to from larger subsystem, which then in turn are linked, sometime in many levels, until a complete top-level system is formed. h) Producer oriented programming and object oriented programming Producer oriented programming main program is divided into small parts depending on the function. The different part of the program connects with each other by parameter passing most of the function use global data. Object oriented programming main program is divided into small object depending on the problem. Data & function of each individual object act like a single unit. Each object control its own data. Data hiding is possible in OOP which prevent illegal access of function from outside of it. This one of the best advantages of OOP.