Basic Structure of C program

Basic Structure Of  C Program

Programming in C is a difficult task for someone who is completely new to the basic structure of a C program. After completing this tutorial, you would learn how the Structure of C Program looks like and soon you would be comfortable writing your own programs with ease by following our posts. 

Let’s start the Basic Structure of the C program.

The components of the basic structure of a C program consists of 6 parts

  1. Document section
  2. Preprocessor/link Section
  3. Definition section
  4. Global declaration section
  5. Main function
  6. User-defined function section

1.Documentation section

2.Link section


3.Definition Section


4.Global Declaration Section


5.Main function


6.User defined function


To understand the structure of a c programet us look at a simple code that would print the words "Hello World". Read about input and output function(printf and scanf)−

     #include <stdio.h>

      int main()

      {

      printf("Hello World!\n");

      return 0;

      }

The various parts in the above program are

  1.The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include the stdio.h file before compiling the program,few examples of different types of heasder files in c are :

      a.stdio.h [input/output functions].

      b.conio.h[Console Input/Output functions].

      c.math.h[Mathematics functions].

      d.string.h[String function].

  2.The next line int main()  is the main function where the program execution begins. int main() indicates that the main() can return integer type data. When our program is simple, and it is not going to terminate before reaching the last line of the code, or the code is error free, then we can use the void main() function.

  3.The next line printf(...) is another function available in C which causes the message                 "Hello,World!" to be displayed on the screen.

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

  5.Curly braces{} are used to group a set of statements. Often we use them along with  loops and conditional statements in order to avoid confusion.


Post a Comment

0 Comments