C - Program Structure


Let’s look at a simple C program structure so that we can take it as a reference in the upcoming articles.

Given below is a simple C Program:

						
/*This is the first C Program*/

#include <stdio.h>
void main()
{
	printf(“Welcome to the world of C.”);   // Displaying the first message
	printf(“\n Begin with C Programming.”); // Displaying the second message
	return 0;
}

									

The output of the given program will be:


Welcome to the world of C.
Begin with C Programming.								

									

Explanation :

1. The first line of the above program is a comment enclosed between /* & */.

2. The second line references a special file called ‘stdio.h’, which tells a C compiler to include stdio.h file before going to actual compilation. This file is a header file. Each header file consists of some standard library functions supported by C compiler. To use these functions it is absolutely necessary to mention header file in the beginning of the program.

3. The third line has the main() function. This function indicates the starting point of the program. The C program can have many functions, but the starting point is always the main() function.

4. Next we have the opening brace ‘{’. All program statements are written after this brace.

5. Then we have two printf statements which are used for displaying messages. Accompanying the second printf, we see a comment which extends to the next line.

6. The next line return 0; terminates the main() function and returns the value 0.

7. Note that each statements ends with a semicolon. Finally we have the enclosing brace ‘}’ indicating the end of the program block.


  • Print Page