C Program Structure

In here we will learn about C Program Structure, What is the header file? Why should I include it? Hwo to include a header file in c Introducing some of Popular header file In C Programming . What is main function and what is program body .

C programming basic Strucures

Before we start we need to know about basic structure of program .It will help you to write the codes and you can understand codes very easily. Let's have a look on the basic structure:

C programming structure

1.Header File:

The first and foremost component is the inclusion of the Header files in a C program top of your program including .h extension.
May be you are thinking What is the header file? Why should I include it?
Header file is very very important component for c program.You can consider it with human brain.
For an example: Suppose you do not know about cat and never seen before . So it is an unknown animal to you right? If someone asked you about cat then you do not able to say about cat because there is no information about cat in your brain.Now assume you know about cat.If someone ask you about cat now able to say this only because the information about cat is available in your brain.In the same way C Pragram have some reserves words and functionlities like( int, printf(), ).If you do not add the header file it will never understantd what is those words in the other hand if you add header file then the Compiler will understand what should do with these words.

Syntax to include a header file in c


Lets familar with some of headerfile:

# Header File Description
1 stdio.h Basically stdio stands for Standard Input And Output . std for Standard and io for Input and Output .It defines core input and output functions like scanf(), printf()
2 stdlib.h It defines numeric conversion functions, pseudo-random network generator and memory allocation like alloc() which is for dynamic memory allocation.
3 string.h It defines string handling functions like strlen() for counting for string length
4 math.h It defines common mathematical functions like sqrt() which is root function

[Note:Not only these header file but also lots of header file available for a specific work]

2.Main function:

Remember program always starts from the main function.It defines from where program should start.Now you can say first you need to add a header file then you need to define or add the main function.

Syntax of including main function:

  int main()

3.Program Body:

Program body starts with the opening curly brackets { right after the main function and end with the closing carlibrace } .In between the opening and closing curly brackets we need to write the codes that we wants.

Lets see how to write:
  int main()
  {//start program body
    int a = 5;
    printf("Number is: %d",a);
    return 0;
  }//end program body


  Number is: 5