Definition:
“Basic structure is defined format for a C language”.
“It is sequence of steps to define the C program for its successful execution”.
In simple words , we can say that a C have some structure in which a program can be execute. Now the question is come in your mind that what is program in c language.
Program: program is set of instruction followed by the programmer to solve the computational problems.
C language program can be developed from a general structure as described below.
1. Documentation section:
In this section,we write the non executable statements. These lines also non as comment lines. This is optional section.
The general syntax is:
/*comment lines*/
2. Preprocessor directives:
There are compiler preprocessor statements. These are also optional statements. But becomes compulsory if your complier has INCLUDE and LIB subdirectories in the specified drive TC. Pre-compiler statements have two sections.
One is link section, in which we can link the compiler function like printf(),scanf(),clrscr()etc with the INCLUDE subdirectory having header files like stdio.h, conio.h, math.h etc.
The general syntax is:
#include<name of header file>
Or
#include”name of header file”
The second section is definition section, in which we can definr a variable with its value. The syntax of definition section is below:
#define variable name value
3. Global declaration section:
We declare some varibale outside the main function,are known as global variables. The global variables are automatically initialized with zero,hence there is no garbage value. The global variables are alive to whole the program. Basic syntax is:
Data type v1,v2…….vn;
4. main()
main() program is the C-program’s main structure in which we process some statements. It is defined as below:
5. Beginning of the main program:
{
(main program can be done using left curly brace “{” ).
A. Local variable declaration:
Variables which are used in the main program are declared bu using the variable declaration statement having local varibles.
Local variables are declared as:
Data type v1,v2…..vn;
B. Executable statements:
This section has reading,writing and processing statements having input/output function,library function,formulas,looping statements and function calling statements.
6. Ending of the main function:
}
( with the right curly brace “}” we can end thw main function).
7. User defined function
We define the function sub-program or calling program,which are called by a calling statement from the main program. Those functions which are defined by the user according to user requirement,are called user defined functions.
Syntax of user defined function is :
type function function-name(parameter)
{
local declaration;
executable statements;
Return(argument);
}
Example: A C-program to add the two numbers using above structure.
/*program to add two numbers*/
#include<stdio.h>
#include<conio.h>
#define M 20
int a;
main()
{
int b;
printf(\n enter the value of a and b”);
scanf(“%d %d”, &a,&b);
int c=a+b;
printf(“addition is %d”,c);
getch();
}
If you have some questions related to the topic the you can ask me by comment the below.
No comments:
Post a Comment