C++ FIRST PROGRAM

Hello World Program

C++ Hello World Program

#include <iostream>
using namespace std;
int main()
{
    cout << "Hello World!" << endl;
    return 0;
}

#include <iostream>

iostream is the header file with a set of instructions for INPUT/OUTPUT. #include tells the preprocessor to include these header files.

using namespace std

Let's assume there are two students in the classroom with the same name 'jack'. To differentiate between them, we can include last name or place name.

There may be a chance to have the same function name in different libraries. To differentiate between the two functions have the same name, namespace came into the picture.

   Std is a standard namespace which has functions like cin, cout, endl. The keyword 'using' means we can use namespace wherever we want in the program. If we don't use 'using namespace std', we need to explicitly call like std::cin, std::cout, std::endl. Following are the examples for 'with' or 'without 'using namespace std

with 'using namespace std'

#include <iostream>
using namespace std;
int main()
{
    cout << "Hello World!" << endl;
    return 0;
}

without 'using namespace std'

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

int main() is a fuction

For everything, there is a starting point and ending point. For example, in the text file start point is the starting line, so we start reading at the first line, but coming to the C++ program starting point is the "int main(){-----}" function.

   The actual execution of c++ program starts from main() function.'int' is the return type of the function. Every function has a return type. 

cout << "Hello World!"; 

cout is the output function written in std. It will print text right side to <<(insertion operator). In this, it prints the Hello World! on console when running the program

return 0 ;

'return 0 ; '  is the end of the function. Every function has a return statement except the function which has 'void' as return type. In 'int main(){----}' function return type is 'int', so we want to return some integer value. that's why we return 0 in our program. You can learn more about returning value in C++ FUNCTIONS page

curly braces {}

Curly braces are used to define the block of the code

semi colon (;)

We need to put a semicolon(;) at the end of every line. If you don't put a semicolon, you will get an error 

 Contact Us:

                  codecalculatenr@gmail.com

 

About Us : 

        Code Calculate is the biggest online platform