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

Discussion in 'Other Languages' started by admin, Jan 5, 2017.

  1. admin

    admin Administrator Staff Member

    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.

    C++ program to print “Hello World”
    #include <iostream>
    using namespace std;
    int main()
    cout<<“Hello World”;
    return 0;
    Output of the above code is:

    Hello World

    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++:


Share This Page