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: A header file serves as a library containing various predefined functions and constants in C or C++. By including a header file in our program, we gain direct access to the pre-defined functions and constants encapsulated within 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




No comments: