by Dinesh Thakur Category: Function and Pointer

The main () is a special function that marks the beginning of the program. The type int before main signifies that function main () returns an integer value to the system on its completion.

In C as well as in C++, the parentheses () after an identifier or a name signify that the identifier or the name on the left of the brackets is a function. Similar to the declaration of variables, the functions are also declared with different types. However, with main () only two types are used: int main () and void main (). The int type functions always return a whole number and the last statement of the function is return value; In case of int main (), the last statement is return 0;. The successful execution of the program function int main () will return 0 to the system. In case of void main (), the return statement is not required. However, compilers for C also allow the use of only main () and without a return statement. In C++ language, however, main () would be taken as int main () by default and the return statement would be required. The body of the program starts after main ().A program may consist of many statements and expressions that are placed between a pair of curly brackets { } after main () as illustrated below.

int main () {\* statements*/}

A function may or may not have arguments. Therefore, main() is also written either simply as above or with two arguments as given below.

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

{/* statements */}

Here, we shall take the first declaration, that is, int main (){}.Remember that every program in C must have one and only one main () function. A program may define or call any number of other functions but can have only one main function. The body of the function main (), as discussed above, starts with the left brace({) after the main ()and ends with the last right or closing brace(}) at the end. Between these two braces a program may contain several pairs of braces { }, each pair may contain a block of statements.

The function printf (), is a function of C Standard Library and is used for displaying the output on the monitor. In the present case, it displays the statement enclosed in double quotes on the monitor. You must have noted that the output of the program does not contain the character "\n", which is the new line character (or escape sequence). Any statement written on the right hand side of "\n" would be displayed in next line. Similarly, "\t" is another escape sequence that shifts the curser a few spaces ahead in the same line.

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