Difference c & Cpp

 

Since C is a procedural programming, it is a function driven language.

C++ is an object driven language.

In C, functions cannot be defined inside structures

In C++, functions can be used inside a structure.

C uses functions for input/output. For example scanf and printf.

C++ uses objects for input output. For example cin and cout.

C does not provide direct support for error handling (also called exception handling)

C++ provides support for exception handling. Used for errors that make the code incorrect.

C does not support reference variables.

C++ supports reference variables.



#include <iostream>
using namespace std;

int main() 
{
    cout <<"Hello World.";
    return 0;
}

 

#include <iostream>: This is a header file library. <iostream> stands for standard input-output stream. It allows us to include objects such as cin and cout, cerr etc.

 

using namespace std: Means that names for objects and variables can be used from the standard library. It is also used as additional information to differentiate similar functions. 

 

int main(): The function main is called just as in C. Any code inside its curly brackets {} will be executed.

 

cout: is an object used to print a particular text after << in quotes. In our example it will output "Hello World". (for personal reference we can say it is similar to printf in c)

 

return 0: Terminates the function main

 

Note:

1) Every C++ statement ends with a semicolon ';'

2) Compiler ignores white spaces. Multiple line spaces are used to make the code more readable.

 

Omitting Name spaces:

C++ programs run without the standard namespace library. This can be done by writing std keyword followed by :: operator inside int main()

Example:

#include <iostream>
int main()
{
    std::cout <<"Hello World";
    return 0;
} 

Comments

Popular posts from this blog

Speech Emotion Recogination