C PROGRAM STRUCTURE:
Different programming languages have their own format of coding. The basic components of C program are
- main()
- pair of curly braces {,}
- declarations and statements
- user define functions
C PROGRAM STRUCTURE
PREPROCESSOR STATEMENTS GLOBAL DECLARATION; main() { DECLARATIONS; STATEMENTS; } USERDEFINE FUNCTIONS |
PREPROCESSOR STATEMENTS:
These statements are begin with symbol# and are also called preprocessor directives. These statements tells the compiler that before actual compilation include header files and symbolic constants in C program.
PREPROCESSOR STATEMENTS
PREPROCESSOR STATEMENTS
# include<stdio.h> : for the standard input/output functions # include "test.h" : for file inclusion of header file test # define NULL 0 : for defining symbolic constants ,NULL=0 # include<conio.h> : for the console input/output |
GLOBAL DECLARATION:
Functions or variables who existence is known in the main() function and other user define functions called global variables or global functions and their declaration are called global declaration. Global declaration should be made before main().
main():
As the name itself indicate that this is the main function of every C program. It should be written in lowercase letters and not terminated with semicolon ;. Execution of every C program starts from the main(). No C program executed without main().
NOTE:There must be single main() function in every C program. It calls user define functions and other library functions. BRACES:
In every C program pair of curly braces are used. The right brace shows the end of the main() function while left brace shows or indicate the starting of main() function. These braces also indicates the beggning and end of user define functions.
DECLARATION:
Arrays, function , variables are used in C program are declared and initilized with their basic data types.
STATEMENTS:
Since we all know computer is a machine and doesnot think itself. We have to provide some instruction to the computer to perform task or specific operations. Instructions may be arithmetic statements,control statements, input output statements and other statements. They include comments which are explanatory notes of instructions. The format of these instructions are /* and */ . Comments are not executed and compiled.
USERDEFINE FUNCTIONS:
As the name incates userdefine means these functions are defined by user and contains a set of statements to perform specific task. Userdefine function are written before or after the main() function.
EXAMPLE OF SIMPLE C PROGRAM:
#include<stdio.h>
main()
{
printf(" WELCOME TO C /n");
}
OUTPUT OF PROGRAM
WELCOME TO C
Explanation:
First line tells the compiler to include header file that is standard input/output file to perform reading and printing the data. Second line is main() that is main function of C Program. Body of C program contain only one statement that is
printf(" welcome to c/n")
When the statement is executed main() calls printf() and printf() is included in header file that is<stdio.h>. The printf() prints Welcome to C on the screen of computer.
0 Response to "Structure of C Program"
Post a Comment