Program Structure

Let us look at structure of a C program

A C program consist of following parts:

  • Preprocessor Commands
  • Functions
  • Variables
  • Statements
  • Comments
  • Let us look at a simple code that would print "Hello World"

        
    #include <stdio.h>
    int main() {
    	/* First C program */
        printf("Hello World");
    
    	return 0;
      }
    
        

    Now, Take a look at various parts of program...

    1. First line of program #include <stdio.h> is a preprocessor command, that tells the C compiler to include stdio.h file before actual compilation.
    2. Next line int main() is the main function. It is the beginning of a program execution.
    3. Next line /*....*/ will be ignored by compiler. These lines are called comments.
    4. The next line printf(...) is a function that prints the message.
    5. The next line return 0; terminates the main function and return the value 0.

    Post a Comment

    0 Comments