Professional Documents
Culture Documents
2.overview of C
2.overview of C
Introduction
C is well suited for writing both system software and business packages
C is highly portable
Why Study C?
Format of simple C programs
Every program must have exactly one special function named as main ()
All the statements between the two braces form the function body
#include<stdio.h>
int main()
{
//......1st Print Line.......
printf("\n hello world");
//......2nd Print Line.......
printf("\n welcome");
return 0;
}
Sample Program
#include<stdio.h>
int main()
{
//......1st Print Line.......
printf("\n hello world, \n welcome");
return 0;
}
Some Commonly Used Terms
Some important points
C is a free-form language
A proper indentation of braces and statements would make a program easier to read and
debug
Another Program
//Program Addition
#include<stdio.h>
int main()
{
int number; Declarations
float amount;
number=100; Assignment
amount=30.75+75.35;
printf("\n number=%d", number);
printf("\n amount=%5.2f",amount);
return 0;
}
Some important points
In C, all the variables should be declared before its use, i.e. to tell the compiler about the
data type of those variables
%5.2f – the output must be in floating point, with five places in all and two places to the
right of decimal point
Desirable Programming Style
Clarity
The program should be clearly written.
It should be easy to follow the program logic
Program documentation
Insert comments in the program to make it easy to understand
Never use too many comments
Program indentation
Use proper indentation
Structure of the program should be immediately visible
Indentation Example: Good Style
Indentation Example: Bad Style
Executing a ‘C’ Program
Creating or writing the program
Link the program with functions that are needed from C library