Structure of c program

Execution any c program starts from main function and end with any null statement. It is good practice to return zero by main function. Which indicates the operating system that program has terminated successfully.

Header file: It is library which keeps various predefined functions and constants. If we include header file we can directly use pre-defined function of that library.

Simplest structure c program:  

#include<stdio.h>  //Header file
int main(){   //beginning of main function.
    printf("Hello world");  //Predefined function.
    return 0;  //returning a value main function.
}  //End of main function

Other basic structure of c program: 

#include<stdio.h>   //Header file
int main(){        //beginning of main function.
    int a,b,sum;   //Declaration of variables.
    scanf("%d %d",&a,&b); //Predefined function.
    sum = a + b;
    printf("%d",sum);  //Predefined function.
    return 0;  //returning a value by main function.
}  //End of main function

Post a Comment