CPP

Structure of C++ program

Probably the best way to start learning a programming language is by writing a program. Therefore, here is our first program: 

Syntax:

#include<iostream.h>
int main()
{
    .........;
    return 0;
}

Example:

#include<iostream.h>
//main() is where program execution begins.
int main()
{
    cout << "This is my first C++ Program!";
    return 0;
}

Output:

Command Prompt
This is my first C++ Program!

Let us look at the various parts of the above program:

  1. The C++ language defines several headers, which contain information that is either necessary or useful to your program. For this program, #include<iostream.h> header is needed. this header file is included for Standard I/O (input output) function.
  2. The next line //main() is where program execution begins. is a single-line comment available in C++. Single-line comments begin with // and stop at the end of the line.
  3. The line int main() is the main function where program execution begins.
  4. The next line cout << "This is my first C++ program!"; causes the message "This is my first C++ program" to be displayed on the screen.
  5. The next line return 0; terminates main() function and causes it to return the value 0 to the calling process.



Subscribe us on Youtube

Share This Page on


Ask Question