Structure of basic C program

Structure of C Program

#Every C program can be written with the following syntax.

Syntax

#include<headerfilename.h>  --> include section
Returntype function_name(list of parameters or no parameter)  --> user defined function
{
Set of statements
.........
}
Returntype main()  --> main block or main function
{
.........
.........
}

Include section

# include is a pre-processor directive can be used to include all the predefined functions of given header files into current C program before compilation.

Syntax

#include<headerfile.h>
C library is collection of header files, header files is a container which is collection of related predefined functions.

User defined function section

If any function is defined by the user is known as user defined function. Function is collection of statement used to perform a specific Operation.

Syntax

Return_type function_Name()
{
....... // called function
.......
}
In the above syntax function name can be any user defined name, return type represents which type of value it can return to its calling function.

Syntax

functionName(); // calling function
Note: User defined function are Optional in a C program.

Main function

This is starting executable block of any program (it is always executed by processor and OS ). One C program can have maximum one main() the entire statements of given program can be executed through main(). Without main() function no C program will be executed.

Syntax

Returntype main()
{
......
.....
}
If return type is void that function can not return any value to the operating system. So that void can be treated as no return type.

Example

#include<stdio.h>
#include<conio.h>

void main()
{
printf("Hello main");
}

Output

Hello main

IO statements in C language

IO represents input output statements and input statement can be used to read the input value from the standard input device (keyboard), output statement can be used to display the output in standard output device (Monitor) respectively. In C language IO statement can be achieve by using scanf() and printf().

0 comments: