Basic Structure of C Program
#include<stdio.h>
#include<conio.h>
void main ()
{
printf(“Hello World”);
}
It has two parts:
·
The preprocessor
directive.
·
The main
function.
Preprocessor directive:
‘# ‘indicates that is instruction for the compiler.
A preprocessor directive is
always start with the symbol (#). In the above program ‘include’ is a
preprocessor directive.
Many actions that is
necessary for the program are not defined directly in a C program. In the above
these action are defined in the form of functions in different libraries. Each
library has a standard header file, which is referred to with .h extension.
‘stdio.h’
is a header file that contains standard input and output functions.
Types:
·
#include
directive for defining identifiers from standard libraries.
·
#define directive
for defining constant macros.
#include directive for defining
identifiers from standard libraries:
Syntax:
#include<standard header file>
Examples:
Some examples of header files
are:
#include<stdio.h>
#include<conio.h>
#include<math.h>
The include directive tells the compiler where to find
the meaning of standard identifiers (printf) used in t.he program. Theses
meanings are described in files called standard input and output function.
#define directive for defining
constant macros:
Syntax:
#define
macro_name expression
Examples:
#define PI
3.14
#define sec_mint
60
Constant macro:
“Constant macro is a name that is replaced by
a particular constant value before the program is sent to the compiler.”
The expression may be
constant, arithmetic expression or a string. C preprocessor replace each
occurrence of the identifier macro _name with value of expression. The value of
macro_name can not be change during the program execution.
Function main:
Main () is a function where the execution of the program are started.
Every program has a main () function. It acts like a main gate of a house.
Main () is a starting point of program instructions. It is a entry point
of the program.
The definition of the main function is always start
with a reserved words (function return type) like (void, int , float and char)
that are also data types
Syntax:
void main()
{
Body
of main function
}
Void
functions, also called non-value-returning functions, are used just like
value-returning functions except void return types do not return a value when
the function is executed. The void function accomplishes its task and then
returns control to the caller.
Body of the function:
It
consists of C language statements, which are used to implement the program
logic. It is enclosed in braces.
Delimiters:
After a main () function the instructions are
written in the parenthesis {}. The rest of the lines of program form the body
of the main function, the body is started by the opening parenthesis and end by
the closing parenthesis.
Braces indicate the beginning and end of the
function body. These braces are called delimiters.
Statement
Terminator:
Every statement in a
C++ program terminates with the semicolon (;). If any of the statement missing
the statement terminator, the compiler will report an error.
Function printf:
printf
function is used to display the output of the program on the console screen.
Syntax:
printf(“string”,variable1,variable2,……);
printf(“string”);
printf(variable1,variable2,………);
Example:
printf(“Hello World”);
Comments
Post a Comment