Basic structure of c program

Basically, every C program has two major sections.

Header section

Main section




Header Section (Why we use header files in c)

In this section, we will include some of the standard header files. Header files consist of multiple pre-written codes.

Example

stdio.h It will have all the information about i/o related functions definition.If our c program needs to say something to the user or get some input from the user, we should use printf and scanf function accordingly.

whenever we need to use input and output related (ex. printf/scanf) functions in our program, we should include stdio.h header file.

Likewise, math.h - will have all mathematical functions' definition.Using math.h header file we can calculate, the square root of a number,power(x,y) i.e. xy etc.





Main section (Why main function is used in c)

Every C program must have a main function.

Main function is the starting point of the program execution.


Wherever the main function is, it will be called first.So main function is the heart of C program.

Example


Example

#include<stdio.h>       //header section

int main()             //main section
{
    return 0;
}




Useful Resources

https://en.wikipedia.org/wiki/C_mathematical_functions
https://en.wikibooks.org/wiki/C_Programming/stdio.h

Topics You Might Like