Structure of C Program

 BASIC STRUCTURE OF A C PROGRAM:

Structure of C program is defined by set of rules called protocol, to be followed by programmer while writing C program. All C programs are having sections/parts which are mentioned  below.

  1. Documentation section
  2. Link Section
  3. Definition Section
  4. Global declaration section
  5. Function prototype declaration section
  6. Main function
  7. User defined function definition section

C PROGRAM TO COMPARE ALL THE SECTIONS:

You can compare all the sections of a C program with the below C program.

#include <stdio.h>

int main() {
   /* my first program in C */
   printf("Hello, World! \n");
   
   return 0;
}
  • The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation.
  • The next line int main() is the main function where the program execution begins.
  • The next line /*…*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.
  • The next line printf(…) is another function available in C which causes the message “Hello, World!” to be displayed on the screen.
  • The next line return 0; terminates the main() function and returns the value 0.

STEPS TO WRITE C PROGRAMS AND GET THE OUTPUT:

Below are the steps to be followed for any C program to create and get the output. This is common to all C program and there is no exception whether its a very small C program or very large C program.

  1. Create
  2. Compile
  3. Execute or Run
  4. Get the Output

Run code and see…..

Advertisements