In C++ Syntax

SYNTAX IN C++ 






 The following code is written in C++

We shall look at each element of the following code in detail to understand the syntax of C++


EXAMPLE - #include <iostream>

using namespace std;

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


HERE we explain it -

#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.


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

Add two number using class in c++ .

DATA types in C++ languages .