Wednesday 7 November 2012

Differences between C and C++:


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.

Introductions of C++



History of programming approaches:

At each critical point in the evolution of programming, a new approach was created to help the programmer handle increasingly complex programs.
The first programs were created by toggling switches on the front panel of the computer.
This approach is suitable for only the  smallest programs.
Next, assembly language was invented, which allowed longer programs to be written.
The next advance happened in the 1950s when the first high level language (FORTRAN) was invented.
By using high level programming language, a programmer was able to write programs that were several thousand lines long.
However the method of programming was ‘anything’ goes approach. It yields unreadable and unmanageable code.
Next invention is structured programming languages in the 1960s.
C is a structured programming language as it contains control structures, code blocks and absence of goto (or at least minimal use).
To allow more complex programs to be written, a new approach of programming is needed. So the object oriented programming was invented.
OOP takes the best of the ideas embodied in structured programming and combines them with powerful new concepts that allow you to organize your program more effectively.

Inventions of programming languages:
In 1940s, Assembly language was invented which is a machine level language; also it comes under low level language.
In 1950s, FORTRAN was invented. It is first high level programming language that is machine independent language.
In 1966, BCPL was invented by Martin Richards. BCPL stands for Basic Combined Programming Language.
In 1969, B language was developed by Ken Thompson. He is also know as developer of UNIX operating system.
In 1972, C language was developed by Dennis Ritchie at AT &T’s Bell Lab, New Jersy USA.
In 1979, C++ language was developed by Bjarne Stroustrup. Initially C++ was pronounced as C with classes.

Some Points about C++:
C++ was developed by Bjarne stroustrup in the year 1979 at AT and T’s Bell Labs, New Jersey USA.
C++ is an enhancement in C, so it consists of all the features that C provides.
Initially C++ was known as ‘C with classes’.
In the year 1983, it is named as C++.
C++ is also a middle level language just like C.