STRUCTURE OF, 'C ' PROGRAM
Before understanding the structure of C program you must know these important points:
* 'C' is a case-sensitive language, it means all the keywords must be written in lower case.
* Keywords can't be used as variable or functions name.
* Every interaction should end with (;)sign:
* Preprocessor main ( ) is must for a program.
* Open function main ( )
* Assign data type and Variables.
* Define the body of the function
* End the function main ( )
#include<stdio.h>
void main()
{
int a=10, b=15, c;
printf("HELLOW STUDENTS"\n");
c=a+b;
print ("the sum of %d and %d is %d, a,b,c);
}
NOTE: THIS PROGRAM WAS ONLY TOLD TO EXPLAINATION TO YOU.PLEASE DO NOT PAY ATTENTION TO IT'S OUTPUT.
IN THE ABOVE EXAMPLE THE FIRST LINE.
/*harsh.c first exmple for students*/
is a comment and non-executable.Comment in 'C' begins with (/*) and ends with(*/).
#include<stdio.h>
is a preprocessor directive. The preprocessor processes the 'C' program before the compiler. Here stdio.h is a header file consists of standard I/O Function. A header file related to the function used in the program should be included at the beginning.
Indicates "the beginning of the program".The compilation of the program starts from main( ) function.
{, symbol indicates the beginning of main() function.
int a=10,b=15,C;
is for declaration of Variables and data types.
Imp:- int included the only real number.
Printf("The sum of %d and %d is %d,a,b,c);
are the body of the program.
and symbol '}' indicates end of main ( ) function.
NOTE: THIS PROGRAM WAS ONLY TOLD TO EXPLAINATION TO YOU.PLEASE DO NOT PAY ATTENTION TO IT'S OUTPUT.
NOW TO WRITE A PROGRAM IN 'C' WE NEED TO FELLOW THESES STEPS:
* Define preprocessor directive ( include header files according to prototype Function, standard I/O library function to be used).* Open function main ( )
* Assign data type and Variables.
* Define the body of the function
* End the function main ( )
EXAMPLE
/* Harsh.c: the first example for students*/#include<stdio.h>
void main()
{
int a=10, b=15, c;
printf("HELLOW STUDENTS"\n");
c=a+b;
print ("the sum of %d and %d is %d, a,b,c);
}
NOTE: THIS PROGRAM WAS ONLY TOLD TO EXPLAINATION TO YOU.PLEASE DO NOT PAY ATTENTION TO IT'S OUTPUT.
Explanation
First line
IN THE ABOVE EXAMPLE THE FIRST LINE.
/*harsh.c first exmple for students*/
is a comment and non-executable.Comment in 'C' begins with (/*) and ends with(*/).
Second line
#include<stdio.h>
is a preprocessor directive. The preprocessor processes the 'C' program before the compiler. Here stdio.h is a header file consists of standard I/O Function. A header file related to the function used in the program should be included at the beginning.
THE LINE
void main( )Indicates "the beginning of the program".The compilation of the program starts from main( ) function.
{, symbol indicates the beginning of main() function.
The line
int a=10,b=15,C;
is for declaration of Variables and data types.
Imp:- int included the only real number.
The Lines
Printf("The sum of %d and %d is %d,a,b,c);
are the body of the program.
and symbol '}' indicates end of main ( ) function.
NOTE: THIS PROGRAM WAS ONLY TOLD TO EXPLAINATION TO YOU.PLEASE DO NOT PAY ATTENTION TO IT'S OUTPUT.