- HubPages»
- Technology»
- Computers & Software»
- Computer Science & Programming
The basic structure of C program
Introduction of basic structure (C)
The format of writing C program is called its statement. The basic structure of a C program is very flexible. It increases the power of the language it consists of following part.
Part of basic structure (C)
preprocessor directive
Main() function
Program body (C statement)
Preprocessor directive
preprocessor directive is an instruction given to the compiler before the execution of actual program. Preprocessor directive is also known as compiler directive. The Preprocessor directive are processed by a program know as preprocessor. It is part of C + + compiler. It modifies C source program compilation. The semicolon is not used at the end of preprocessor directive.
The preprocessor directive start with hash symbol # and the keyword includes or define. This directives are written at the start of program. The preprocessor directive is used in C to include header file in the program
Main() Function
The main function in the place where the execution of a C program starts. When the program is executed, the control enters main() function and starts executing its statements.
Each program must contain main() function. If a program does not contain main function, it can be compiled but cannot be executed. Any number of statements can be written in the body of the main() functions. The body is enclosed in braces {}
Syntax
The syntax of main() function is as follows:
void main(void)
{
body of main function
}
The main functions consists of the following:
- The definition of main function is start with keyword void. It indicates
the type of value that is returend by function void means that the
function will return no value.
- Keyword void in parenthesis indicates that function does not
accept any argument.
- The body of main function is enclosed in braches. It consists of C
language statement.
- The instruction are used to implement program logic.
Program body (C Statement)
A statement in C language is an instruction for the computer to perform a task. This statement are written in curly brackets. Computer perform these instruction one by one in the same sequence in which these instruction are written. Each statement in C is terminated the semicolon.
Example
The following example contains two statements in the body of
main() function.
#include <stdio.h>
void main()
{
printf("Hello World of C Programming.")
printf("Programming makes life interesting.")
}
Preprocessor Directive
| Main() Function
| Program body (C Program)
|
---|---|---|
Preprocessor directives are lines included in a program that begin with the character #
| The main function serves as the starting point for program execution.
| Most statements in a typical C program are simple statements of this form.
|
Which make them different from a typical source code text.
| It usually controls program execution by directing the calls to other functions in the program.
| Other examples of simple statements are the jump statements return, break, continue, and goto.
|
They are invoked by the compiler to process some programs before compilation.
| A program usually stops executing at the end of main, although it can terminate at other points in the program for a variety of reasons.
| A return statement specifies the return value for a function (if there is one), and when executed it causes the function to exit immediately.
|
This content is accurate and true to the best of the author’s knowledge and is not meant to substitute for formal and individualized advice from a qualified professional.
© 2020 Hadiya Mughal