What is the difference between C and C++ programming languages

Let’s consider the following C++ program which prints “Hello World” on to the console or terminal window. We will look at various elements used in the program.
Output of the above code is:

In the above program, iostream is the name of a header file which contains I/O functionality. In order to take input and print some output using our C++ program, we have to include that header file using #include directive. Note that writing “.h” at the end of the header file name results in an error. Such style is deprecated in newer versions of C++.

The cin and cout elements are declared in std namespace inside iostream header file. So, to use either cin or cout, we have to write using namespace <name>. If you don’t want to write this line, you have to write std::cin and std::cout in your program instead of cin and cout.

Every C++ program must contain a main() function which specifies the starting point of execution. Since return type of main is int, you should return an integer value back in your program.

cout is the standard output object. It is used in conjunction with insertion operator (<<) to print output on the screen.

The return statement returned a value 0 which tells the operating system that the program has completed successfully. A non-zero value tells that the program execution was unsuccessful.

Finally, the first line is a comment. We can write single line comments in C++ using // and multi-line comments using /* and */.

Differences between C and C++

Following are various difference between C and C++:
If you have any question so you can ask in comments below .


EmoticonEmoticon