1. Lecture 2
Programming in C language
VIDYA CLASSES
Asstt. Professor
Department of computer science and IT
2. Introduction of c
• In 1960 B language (Basic combined programming language)
was developed
• Modified by DENNIS RITCHIE at bell laboratories in 1972
3. Importance of c
• It is strong language whose functions and operators can be used to write
any complex program
• Programs written in c are efficient and fast due to it’s variety of data
types and powerful operators. It is many time faster than basic
• In c many standard functions are available which can be used for
developing programs
• C is highly portable it means that c programs written for one computer can
be run for another
• Basically c is collection of function that are supported by c library .We can
continuously add our own functions to the c library so it’s ability to extend
itself
4. Basic Structure of c Program
Documentation Section
Documentation Section
Link section
Defination Section
Global Declaration Section
Main() Function Section
{
Declaration part
Executable part
}
Subprogram Section
Fun 1
Fun 2
.
.
.
Fun 4
5. eg.
/* To find circumfarance of circle*/
#include<stdio.h>
#include<conio.h>
# define pi 3.14
main()
{
float c,r=5;
c=2*pi*r;
printf(“circumfarance=%f”,c);
getch();
}
6. Character Set
• Letter
Uppercase A……Z
Lowercase a….z
• Digits
0…..9
• Special Character
Comma,colon,question mark
• White Space
Blank space,horizontal tab,newline
7. Tockens in C
Smallest individual units are called tockens .Their are 6
types of tockens
• Keywords
eg. Auto , char
• No to identifiers
eg. A(n),B(n),name,variable,function
• Constants
eg.50,-23.7
• String
eg. “kalyan”, “data”
• Special Symbol
eg.{},[],#
• Operators
eg. +,-,*
8. Executing a c program
• Creating the program
• Compiling the program
• Linking the program with functions that are needed
from the c library
• Executing the program
9. Constant
Whose value does not change
Constant
Numeric constant Character Constant
Integer constant Real constant
Single character constant string character constant
10. Rules for constructing integer constant
• An integer constant must have atleast one digit
• It must not have a decimal point
• It could be either +ve or –ve
• If no sign precedes an integer constant it is assumed to be +ve
• No commas or blanks are allowed within an integer constant
• Range for integer constant is -32768 to +32767
11. Rules for constructing Real constants
• A real constant must have atleast one digit
• It must have a decimal point
• Default sign is +ve
• No commas or blanks are allowed within a real constant
12. Single character constant
• These are contains single characters enclosed within a pair of
single quotation mark like ’ s’, ’z’, ’a’
eg printf(“%d”,’a’)
String character constant
• A string constant are enclosed in double quotation . Like
“kalyan”
13. Keywords of c
• Keyword is a reserve word of compiler or they
are already explain to the compiler
Like auto , double ,static , break ,else ,int , struct,
case, long ,switch, char, extern ,const, float etc
Variable
• A variable is a data name that may be used to
store a data value.During the execution of a
program a variable may take different values at
different times during execution