Coupon Accepted Successfully!


Illustrative simple program in C++ without class

  • Every C++ program executes from the main().
  • Opening and closing braces are used for the beginning and ending of the program, respectively. Braces must be balanced. The number of opening braces should be the same as that of closing braces.
  • The flow of the program can be followed by proper documentation. One can use comments in the program. A comment statement starts with two successive back slashes with no space between them, i.e. it begins with a double slash symbol(//) in the program statement as shown in the above program. A comment can be placed anywhere in the line and it does not end with any symbol.
    Comment symbols similar to those used in C++ can also be used. In C, comment symbols /* and */ are used in programs. These symbols are also permitted in C++ programs.
  • Header files are needed at the beginning of the program; they include the definition of the functions that are used in the program. In the above program #include<conio.h> header file is used, which takes care of clrscr() and the header file #include<iostream.h> helps stream programming feature such as cout and cin .
  • The statement cout<<“\n Hello! Welcome to the world of C++”; displays the string enclosed between the quotation marks and \n escape sequence is used to print the string on the next line.
  • The cout (C out) and << (insertion operator) are the identifiers used in C++.

In C++, int main() returns an integer value to operating system. Operating system checks whether the program is executed successfully. The return value of the function int main() is used for successful execution of the program. If the returned value is zero (0), it means that the program is executed successfully. A non-zero value indicates that the program execution was unsuccessful.

The prototype of main() function in C++ is as follows. The return statement is used in the program at the end of the main() function to return a value. If there is no return statement, the compiler displays a warning message “Function should return a value”. The default int is to be returned to the main() in case int is not specified in the main().


int main();

int main(int argc, char *argv[]);

C++ programs are coupled with class. A class encapsulates data and associated member functions. A detailed description is given in the classes and objects chapter in this book.

Test Your Skills Now!
Take a Quiz now
Reviewer Name