Basic Structure of C-Program
Basic Structure of C-Program
of C-Program
Structure of c-programs
Documentation Section
• The Documentation Section consists of set of
comment lines giving the
Name of the program
The author
Other Details which the programmer would like to
use later
Syntax
/* Multiple Comment lines *\
// Single Comment line
Example
/* c –program to find gcd and lcm of two numbers
using Euclid's Algorithm *\
// Welcome to C
Link Section
• The link section provides instruction to the
complier to link functions from system library
• Syntax
#include<header file name .h>
Header files
stdio– Standard Input /Output
conio– Console input/Output,
math- contains mathematical functions like
(cos(), sin(), sqrt(), abs())
• Example
#include<stdio.h>
#include<conio.h>
Definition Section
• This section is used to define symbolic
constants
• Syntax:-
#define symbolic-name constant-value
• Example:-
#define pi 3.142
#define maxmarks 100
#define minmarks 35
Global declaration Section
• In C There are two types of declarations
1.Local variable declaration
2. Global variable Declaration
• Global variables are declared out side the
main function
• Local variables are declared inside the
main function
Variable declaration
• Syntax:-
data-type variable-name;
Ex:-
int a,x;
float b,c;
char name;
Main() function
• C-program should have at least one
main() function
• Form:-
main()
{
local variables declaration
computation part
logic part
}
Reading data from input
device (keyboard)
• scanf() function is used to read the data from
standard input device
• Syntax:-
scanf(“format specifier”,&var1,&var2-----,&varn)
• Example:-
scanf(“%d”,&a) for int data-type
scanf(“%f”,&b) for float data-type
Print data or variable
• printf() is used to print the variable or
data
• Syntax:-
printf(“ message -format specifier”,var1,var2-----,varn)
• Example:-
printf(“Welcome to c”);
int a=10;
printf(“value of a=%d”,a);
Arithmetic operators
Example:-