Pages

Showing posts with label main() function operation. Show all posts
Showing posts with label main() function operation. Show all posts

Wednesday, July 13, 2011

The main() Function in C and C++

The main() function is an user-defined function. Normally every C/C++ program should have a main() function because it is the entry point of any C and C++ program. The C and C++ compiler start compiling and executing any C and C++ program from the main() function. The compiler first calls the main() function and then the main() function calls all the functions having in its body one by one. The smallest C program is shown below.

void main()
{
   
}

Compiling Result

 
The above program will generate no error or no warning but will produce no output because there is no function inside the main() function's body for executing. But if you execute the flowing code, you will see an output on the screen. 
 
#include<stdio.h>
#include<conio.h> 

void main()
{
   clrscr();
   printf("Hello! I'm a novice in C and C++ programming.");
   getch();


Compiling Report



Program Output