Writing First C++ Program- Hello World Example

C++ is a widely used Object Oriented Programming language and is  fairly easy to understand. Learning  C++ programming can be simplified  into:

// C++ program to display "Hello World"  // Header file for input output functions #include using namespace std;  // Main() function: where the execution of program begins int main() { // prints hello world cout << "Hello World";   return 0; }

“Hello World” on the screen. Let us now look at the program:

INPUT

Output Hello World

This line  is a comment line. A comment is used to display additional information  about the program. A comment does not contain any programming logic.  When a comment is encountered by a compiler, the compiler simply skips  that line of code. Any line beginning with ‘//’ without quotes OR in  between /*…*/ in C++ is comment

1) C++ program to display “Hello World”:

All lines that start with pound  (#) sign are called directives and are processed by a preprocessor which  is a program invoked by the compiler. The #include directive tells the compiler to include a file and #include<iostream>.  It tells the compiler to include the standard iostream file which  contains declarations of all the standard input/output library  functions.

2) #include: In C++,  

This is used to import the  entirety of the std namespace into the current namespace of the program.  The statement using namespace std is generally considered a bad  practice. When we import a namespace we are essentially pulling all type  definitions into the current scope. The std namespace is huge. The  alternative to this statement is to specify the namespace to which the  identifier belongs using the scope operator(::) each time we declare a  type.

3) using Namespace std:

1. Always include the necessary header files for the smooth execution of functions. For example, <iostream> must be included to use std::cin and std::cout. used to take inputs.

Important Points to Note while Writing a C++ Program:

2. The execution of code begins from the main() function.

Important Points to Note while Writing a C++ Program:

3. It is a good practice to use Indentation and comments in programs for easy understanding. 4. cout is used to print statements and cin is used to take inputs.

Important Points to Note while Writing a C++ Program: