by Dinesh Thakur Category: Function and Pointer

In C, program execution starts from the main() function. Every C program must contain a main() function. The main function may contain any number of statements. These statements are executed sequentially in the order which they are written.

 

The main function can in-turn call other functions. When main calls a function, it passes the execution control to that function. The function returns control to main when a return statement is executed or when end of function is reached.

 

In C, the function prototype of the 'main' is one of the following:

 

int main(); //main with no arguments

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

 

The parameters argc and argv respectively give the number and value of the program's command-line arguments.

 

Example:

 

#include <stdio.h>

/* program section begins here */

 

int main() {

// opening brace - program execution starts here

printf("Welcome to the world of C");

return 0;

}/

/ closing brace - program terminates here

 

Output:

 

Welcome to the world of C

 



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article