Basic Structure of A C Program




       The format of writing C program is called its structure. The basic structure of C program is very flexible. It increases the power of language. It consists of following parts:
  • Preprocessor directive
  • Main() function
  • Program body (C statements)
Example
Preprocessor directive ⟶ #include <stdio.h>
                 Main Function ⟶ void main()
                  Program Body ⟶ {
                                                             printf("Hello World.");
                                                       }



In the above example,

  • First line is preprocessor directive to include a header file stdio.h. The preprocessor directives are the commands that give instructions to C preprocessor. Preprocessor is a program that modifies C source program before compilation. The preprocessor directives start with hash symbol #.
  • The second line is main function. The main() function is the place where the execution of C program starts. When the program is executed, the control enters main() function and starts executing its statements.
  • The statements of the program are written in curly braces. The curly brace { is called opening brace and } is called closing brace. The braces are also known as delimiters. These statements are collectively known as the body of a program. Every statement in C program is terminated with a semicolon (;). The compiler generates an error if any statement is not terminated by a semicolon.


Post a Comment

0 Comments