c c++ c# differences

1
217
views
C & c++ Differences

Difference between C and C++:

Change in file name extension:

Every programming language has its own file extension. For C programs, generally we use .C file extension. Similarly, for C++ programs we use .CPP file extension. 

Default header file:

Consider the following c program which can run under popular compilers without any difficulty.

void main()

{

print(“Hello\n”);

}

Standard library function ‘print’ does not require any header files i.e., c language has default header . But in cpp we have to include header file to use it i.e., there is no default header file in cpp.

Stream orientation:

Here, there are two types of streams:

Input stream: For accepting the data.

Output stream: For displaying the data.

Input stream:

In cpp, ‘cin’ object is used to accept data. The object is included in the header . There is no need of explicit address operator and control string character.

Syntax:

cin>>variable_name;

Example:

{

int a;

cin>>a;

cout<<”Value entered is “<<a;

}

Output:

20

Value entered is 20

Output stream:

In cpp the output is displayed using ‘cout’ object. The object is included in the header . The major advantage of ‘cout’ object is that there is no need of string characters such as %d, %c, %s, etc.

Syntax:

cout<

Example:

int a;

cout<<”The value is “<<a;

Output:

The value is 10

Comment lines:

In cpp, you have new types of comment lines. These new comments start with ‘//’. Characters after ‘//’ are considered as comment lines and these are called single lined commands. Cpp even allows both /*,*/.

Example:

//This is a single lined comment line.

/*This is a

multi lined comment line.*/

Constants:

cpp allows declaration of constants with the help of #define_______.

Syntax:

constant  data_type  variable

Scope resolution operator:

To get the idea of what is a scope resolution operator, let us suppose a program.

int a;

void main()

{

int a=200;

printf(“%d”,a);

}

Here the output should be 200. But we cannot access the global value of a. So in cpp this is being overcome by using a scope resolution operator (::).

we don’t have any chance to accers the global variable in traditional’c’ language but in c++,u can access u can access global variable.

:-scope resolutions operator in cpp distingistes global variable and local variable when both are declared with similar name

Syntax:

::variable_name

Example:

int a=10;

void main()

{

int a=100;

cout<<”Value of local a is “<<a;

cout<<”Value of global a is “<<::a;

}

Output:

Value of local a is 100

Value of global a is 10

C#(CSHARP) is easy to learn.It can be used to create almost anything but is particularly strong at building Windows desktop applications and games. This can also be used to develop web applications and has become increasingly popular for mobile development .

Contact admin for more posts and any queries and for health related information Click Here