Structure of C program | C – Program Structure
The best way of learning programming language is by writing programs. before we are going to write any program we need to know the Structure of that programming Language. it will give a clear picture about Language.
Here we are trying to learn Structure of C programming language basically C is the structured programming language. C program is a collection of functions. Every Function is a collection of statements and it will do a specific task.General structure of C program is given below.
Structure of C program :
Function1( argument 1,argument 2)
Local Variables; // Comments
Now we are going to discuss each and every line and it’s meaning and why it is using let’s start with pre-processor Directives.
- Pre-processor Directives is always started with Hash Symbol (#).
- C program is are passed through pre processor before going to Compiler.
- These pre processors directives are used to add Header files to the program.
- The main thing is preprocessor Directives are used to include files to our programs.
- Commonly used Preprocessor Directives are #include and #define.
- #include is used for Including Files Files may be Header files or Normal Files.
- #define is used to Define Symbolic Constants and Macros.
- Generally, we are using stdio.h header file using #include pr processor Directive for including standard input and output files to our program so that we can perform printing values by using printf function and reading values by using the scanf function.
Global Variables :
If we define any variable globally that means out of two functions and above of Main function it will available for main function and Function1.
Main Function :
- Execution of C program is Starts with main function it is starting point of C program.
- Every C program must be have at least one Function if a program has only one function that must be main function.
- We cannot write any c program with out main function. Because program Execution starts with main and Ends with main so it is Mandatory.
- The main function has two parts, Declaration of Local Variables and Statements.
The Scope of local variable is within the Block(function).
C programs are the collection of Statements, statements is an executable part of the program it will do some Action.
- You can find available Statements in C program at Statements in C language.
a = 10; b = 20;
c = add(10, 20);
printf("C : %d t and G Value : %d n",c,g);
int add(int i, int j)
- In above program #include is pre processor Directive it is using to include Header file stdio.h.
- int g =10; is Global Variable is is available for main function and add function.
- main() is main function here we are trying to calculate sum of a and b. addition is performed by add function so i am passing a and b Values to add Function it is calculating sum and returning back to main and main is storing that value in C variable then printing the values of C and g.