STRUCTURE OF "C" PROGRAMMING
Program structure:
Comment section
Preprocessor section
Global declaration section
Function section
Global declaration section
Function section
main()
{
declaration part;
executable part;
}
User defined program
{
body of the subprogram;
}
User defined program
{
}
Comment section
- Single line comment
- Multi-line comment
Multi-line comment */
Preprocessor section
- It starts with a pound symbol (#), Example: #include<stdio.h>
- It is not terminated with a semicolon.
Global declaration section
A global variable is a variable that is declared outside all functions. Global variables hold their values throughout the lifetime of your program and they can be accessed inside any of the functions defined for the program.
Examole program:
int a =10;
int b=9;
public int add()
{
return a+b;
}
Output:
19
Function section
- Main function
# Mandatory for every C program.
Two parts
- The header of the function
- Body of the function
/*Program to Add Two Integers */ // comment section
#include<stdio.h> // preprocessor section
#include<conio.h>
void main() // main() function
{
int a,b,c; //local variable declaration
clrscr(); // executable part of the program
printf("Enter two integers: ");
scanf("%d%d",&a,&b); // calculating sum
c=a+b;
printf(“sum = %d",c);
getch();
}
Output:
Enter two integers: 2 3
sum = 5
No comments:
Post a Comment