Structure of a C Program

The basic C program is as follow

#include<stdio.h>               //i m single line comment
int main(void)
{
       printf("First C program \n");
     /*
         i m multiline comment
     */
       return 0;
}


#include:-C program starts with a preprocessor  directory  .# include is a preprocessor directory and it tends to include the 'stdio'(Standard Input and Output) header file with extension '.h'  to the current program.This header file contains functional information about 'printf' .Compiler will check the following directories

/usr/local/include
     libdir/gcc/target/version/include
     /usr/target/include
     /usr/include
or 
C:\Program Files (x86)\Dev-Cpp\MinGW32\include

If your header file is in different directory then do mention the absolute path.

main:- main is the function in the program from where the execution of a program starts.In C there is a sequential execution from the beginning of the main function ,till its end.Beginning and ending of main is indicated by the opening and closing of curly braces {}.Anything written left to main is its return type.Right to main in braces arguments passed to main are mentioned.Here return zero indicates that nothing is returned by main function although its return type is int.Instead of int you can use void or refer to the data types section for appropriate data type.

printf:- It is a function in stdio header file defined for the standard outputs.Anything written between the double quotes ("") is printed on the console.If you encounter %d or %s in between ,it means that an integer or a string value is to be printed on the screes and the value or the variable name is passed to the function after inserting a comma ,immediately after the double quotes like:
         printf("the value of i is %d",i);

scanf:- It is a standard input function defined in stdio.h.It is used to get input from user.Its format is as follow.
        scanf("%d%s",&a,&c);
an integer value and a string is taken from user and is stored at the memory location indicated by a and c.

0 comments:

Post a Comment