C++ Basic syntax : meaning

Hello world with c++

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



#include<iostream>:

Is a processing directive that includes the content of the standard c++header file iostream.
iostream is a standard library header file that contains definitions
of standard input and output streams.
The standard input /output streams provide the way to get input /give output to an external system(usually terminal).


int main(){...}:


It defines a new function with the name main,  by convention the main function is called upon the execution of the program.
And there should be only one main function in a c++ program. and it must always return an integer.


Here the int in front of main ()/or any function defines the data type which the function gonna return.
note: as the main function is the heart of the program, the value returned by the main function is an exit code.
return 0-->EXIT_SUCCESS
any other return code -->associated with an error

in the above example, we didn't have mentioned any return statement, that's because the main function will return 0 by default if we didn't mention any return specifically.

note:
In C++ all functions other than the one with void data type should return a value according to the functions data type. or not return at all. it can only return the value based on the function's data type.



std::cout << "Hello World!" << std::endl; prints "Hello World!" to the standard output stream:

std is a namespace and:: is the scope of the resolution operator.
here we used:: to mention that we want to use cout from the std namespace.