C Programming Full Course
C Programming Full Course
Level vs
Level language
Low level language High level language
These languages aren't
Machine language
dependent on system
Mateinetta architecture
written in Binary10s andI's
Dependent on system architecture Drawback The computer
Advantage Faster execution has to convert human
readable language to
binary long Machinelong
Assemblyberg Hence slower execution
Languagetranslator
Assembly
Assembler machine
language code
object source
Interpreter
296 compiler code code
d
olp Output
Fifitteragehaving
small language 32 keywords
core as other language are
language many
dependent on C language
portable The code can be run in diff systems
Built in functions operators
structured language modular program
pointers
Extensible language
compilation and execution is faster
Dynamic memory allocation
case sensitive language
used to develop and operate embedded systems
Platform dependent
i.e Windows code cannot be run in Linux
and macos and vise versa
structure of a C
Program
Documentation Section comment section
Ex Author
11 Date Effected
A Program for addition of
two numbers
compiler
This section is optional and is
just to
enhance the of program
reading
Link section
include stdio h
Stdiostandard input output
used to include i print
ii scarf
include conio h
Conio consoled input output
used to include getchC
include math h
include str.us
used to perform operations
ng
Definition section
def pi 3.1459
def Max 200
declaration
Executable
Subprogram section
Exertion Process
of a C
program
source code
Preprocessor
first.i
edit
Compile
syntax
error
first.am No
assembler
first obs
link with system libraries
first exe
Execute
pita
1
logic
and Data
error
Translational
no
linking and
Output model
loading
Constants in C
constants are fixed values throughout the program
Integer 8yd
numeric Hexadecimal
1 Floating Real constants
string constants
Decimal 0 9 Base 10
Integer Octal 0 7 Base 8
Hexadecimal 0 9 A f Base 15
Note
printf Id a
used to print corresponding
print II 97
ASCII values
c 97
Fx printf
Note A 2 65 90 Ofp a
a 2 97 122
0 9 48 57
0 4 6
specialancies 5
note
II
a
Fig
constant
singlecharacter
constant
Variables in C
It is the name of the memory site that stores
a particular value
Declaration of a variable
Datatype variable name
Ex int a declaration
a 10 initialization
we perform
can declaration and initialization in
well
the same step as
Ex.int a 10
void main
a 10
print i d a
getch
Variable can'tbe
Not chara void
97 is stored in void a
IT a Ascii standard
variable name is assigned as per rules for naming
identifiers and standard keywords cannot be used
as variable name
keywords in C
Datatypes in C
Tells the
type of data that has to be stored in the
memory Also it tells us how much storage memory
to be allocated to a variable
Datatypes
PRIMARY
1
Derived user Defined
int
Array typedef
float structure Enumerated DT
char union
double pointers
void
short int
byte Also signed
It_
int Unsigned
long n bytes
1
For 16 bit computer
Range of signed int 32768 to 32767
Range of unsigned Put 0 to 65535
bytes 8 bits
char
signed 128 to 127
char
Unsigned 0 to 255
Eat bytes
8
3.4238 to 3.4 e
declaration
float format specifier
Ex a
II 0
printf a
IP 10.000000
If
double format specifier
8 bytes
Declaration double a
Format specifier 1 Lf
long double 10bytes
a
I 9
Datatype Range Eyes Format specifier
char or signedchar 128 to 127 1 I C
0 to 255 2 C
unsigned chat
ut or signed int 32768 to 32767 2 d
0 to 65535 2 U
unsigned int
Y.lu
signed long int 0 to 4294967295 4
128 to 127 I
Short int
o to 255 I
usigned short int
float 3.4238 to 3 4 38 4 f
double 1 Te308 to 1.72308 8 If
Tong double 3.44932 to
1.104932 10 Lf
int 2 bytes
32768 to 32767 Signed int
0 to 65535 unsigned int
Feldotolo
Fedotoooflowest
5535 7 iF It
highes
32768
032768 2 1,0 1,2 327670
65534
unsigned 8 9k o
int 452
327615
2 32766
1
Examplef
include estdio.tn
include conio h
void main
int a 32767
Urser C
printf Id a
getch
OP 32767
include cstdio.hn
include conio h
void main out of rangewon't be shown
But error signedint
circle
32768 the
int a in 32767
32768
Urser afteroccur
Id a will
printf
getch
0p 32768
include cstdio.us
include conio h
void main
int a 32768
UrserC
a
printf L1
9th unsigned int
the no is in the
range of
0 P 32768 unsigned int
Char Ic 1 byte
Unsigned to 255
lowest
Ifotoooo
nIt
255 highest
include stdio.us
void main
To store the value 11
int a 11 have integerand
we
printf id a number system
getche
other parts tents of a code is stored using
character system according to ASCII standards
characters
1 151 I
Nd char
char i
F 2
include cstdio.us
void main
addressof
char a a
If suppose the
this block is 102
Char b 98 ASCII value of a is 97
char 2 therefore binary value of 97
Chan D 130 will be stored
unsigned d
char 130
Id a therefore Olp is a
printf
It will print integer value
i e 97
include csteho.us
void main
char a a
the corresponding binary
value of 98 will
be stored
Char b 98
char 2
Chan d 130
unsigned d
char 130
include csteho.us
void main
7
They
Chan d 130
unsigned d
char 130
char a a if is mentioned we
nothing
char b 98 take it to be signeddah
char 2
In signed char Max positive
Chan D 130 value in is 127
range
unsigned d
char 130 so in the
signed
chat cird
unsigned chord 129 130 corresponds to 1260
printf Ic d
printf Id d chat
It prints a
E
Increases the value by L
2 Increment operator
int y 10
int
y att I
print f fd y
printf fd x n is updated
and stored
Increment operator
IT
is updated
19H Y
y and stored
a remains
Equality operator
comma operator I
Assignment operator
Operator conditional operator
Ternary
expression 1 expression 2 expressions
is true the flow of control moves to
if exp 1
exp 2
if exp 1 is false the flow of control moves
to 3
exp
int a 10 b 15
Ex
asb a b
cond ha
this operator is similar to that of
if else statements
int a 10 b 7
Usac
printf atb d atb 17
b 1d a b 3
printf a
printf a b I d a b 70
printf a b Id a b Quotient
at b Remainder
printf at b 1 d
getchll
Decrement Operator ft
Increment and
springmpetrator
prefix MRI
Postfix
I increment
post operator
int a 10 y
g in second line
printf Id i e
yttx
int 9 5 b c d
d tta
printf 1 d a
Memory
storage
IT
I
1 by
18 by so
Final output 8
Relational
Eit
Note is an assignment operator
is equality
an
9
78 Ascii value
int 9 18 b 9
Urser prints integer
printt d a b
printf fd c C'b
getches
0P Both false
8
x.PH include stdio.hn
include conio h
void main
int a 18 6 9 c d e 10
Unscr
c b t 0
ii d acbeesd
printf 1d b ei
printf I d Ise
printf I d atc brecard
a b c
a b c d e
a b c d e
I
Ept 0 false
Note arithmeticoperato
1 True
have more precenden
false
than relational
0 false operator
EX.PH includeCstdio.h
include conio h
void mainC
int a 18 5 9 c d e 10 f
Ihsac
ab IF I Go
f as b dec
Id f time to
print L
print f d at c b e ctd 1
trjtmfalse
0 1
0
line 10 is 0
Olp of
balstimning operators it
logical AND
logical
I unary operators Not
int a 10 b 5 values
a b
Éme
False t
Logical AND
Final Ofp O false
EI five basis 88 b 10 ball a 5
printf Id result
0p 1 True
int a 4b 6 result
result alb print python
printf pd result
result
if If Espen
0P 1 True Also in logical and if
first expression gives zero
E 9 10 5 5
Ttf it won't
expression
go to the other
1 111 4 since ab is zero now it checks
0P O the other side
theflowstops
if first side is 1
includesstdio.us
EXPLI
void main
int a y 5 6 result
result as b print Python print Lecture
printf Id result
3
b result
memory is a bit
We can apply these on int and char values but not
on float
Types of bitwise operators
Bitwise and
1 Bitwise or
BITTLEPot complement
Left shift
right shift
t.IE b
soda
a 1010 a b
D
b 101017
f
0p O
1 Bitwise OR
5
EX.int a 10 6
c a lb
a 1010 B
b 0101 B
a b 1010 ᵗ
in decimal
Bitwise XOR
Ex int a to 5 5
c a b Note A operation
ᵈa 1010
B
gives
input
0
are
if both
same
b 0101 and 1 foropposite
B
1 0 1 0 input
c a b
101
1 1 1 1 0 1
in decimal
I 1
0
0 p 15
Ex.pgm_ maine
int a 10 b 6
Inscres
I d a b 5 1110
Printf
int a 10
0P
an
Eirik
IN ᵈ
E IOIOL i.de
TRICKY
Trailing bits by
are
C a LC b default filled zeros
by
OP
ax2If and Roundoff
decimal point
Right shift
Kif are c a b
we given
then C
and Roundoff
decimalpoints
it
O P
c
4 2 2
Bitwise Not
int 9 5
b na
Sof 101 B
b 0101 1010 B
B
10
in decimal
Therefore op
Special Operators
mm
separator
int a
Here comma act as an operator
a 5,4
Here we have comma and assignment operator
Assignment happens first higher priority
0P
and then rejected
Jenny Then second value is
2
assigned
into
a print Jenny 2,3
0p Jenny
int 9 8 b
II
b att a
Be
I
Ex int 0 8 b
b att a
a
15
Ga 138
a
Is
Operator Precedence and Associativity
prefix
postfix R I
sizeof type R L 2
L R 3
R 4
LL R 5
R 6
L R 7
R 8
L R 9
I L R 10
R 11
11 LTR 12
R L 13
1 C R L 16
9 R 15
Formatted Input function in C
control string
d or If or C
t
for inputting forfloat for char
infan
E include stdio.is
include Clonio h
main
as
written twice
int b sum
a we are getting 2 inputs
Insors from the user
scant Ted a b
sum atb
note were is address
of operator
will
of 1 d
instead we it
if use a means
d d b
EI n_scant a
sum atb
print sum I d sum
E main
int a b sum
print Enter two numbers
b
scant Id Id a
sum atb
printt Id sum line
I Format integervalue
printing
specifier for
4
a 1234
printt food a
stored as
61010
a 1234
print f a
tiff
This means it can store 10 decimal
digits and 2 digits after the decimal
point
Functions
Unformatted
we
Input we
getchart mains
getche
March
getchel ch _getchart
gets1
print t.ci ch
input
Euthereen skimmo
J Output
It prints only first
was
In getchl the moment we press a chat the control
the next line without displaying
goes to instantly
the character
at the end of all programs
we use getchi
to use it the output
to hold the output If we fail
just flashes the screen and disappears instantly
char ch 10
gets ch
s ch
printf ch
char ch
Enter char
print a
ch getche
printf In character is t.ci ch
getches
enter cue a g
open
character is 5
if
if else
if else if ladder
Nested if
switch
if statement
if condition
statement
after if statements
void main
int a
Enter a
printff
scarf f d a
if a
Ofp Enter a 5
Inside if block
if block
low chart
1
false
Condition
True
statement block
After if statements 4
Note
if we are using multiple statements after
statements
if statement we enclose these
with
E void main
int a
Enter a
printff
scarf f d a
if a
int
age
the age
print Enter
scant Id age
if age 20
time to
print Its go home
getch
0P Enter 15
age
Its time to home
go
Enter age 21
Your age is 21
You can go to office with
me
Its time to
go home
If else
if condition
else
false block statements
after if else block statements
1
false
Condition
True
int age
print f Futer age
scarf fd age
if age 258 age 30
condition 2
if
Inner if blockstatements
else
inner else block statements
else
if salary 260000
salarysalary 1000
else
salary Salary 5000
else
3000
salary Salary
statement 2
else if condition
statement 3
else if condition n
statement n
else
Default statement
statement
Ex Pgm
void main
int marks
print Enter marks
scarf Id marks
if marks 780
printf Grade is A
else if marks 370
print B Grade
else if marks 60
print C grade
else if marks 55
print D grade
else
print f fail
Futer marks 80
C grade
End of program
Switch in C
Multi decision
statement
way
syntax switch expression
case value t
Block of statements
break
Case value 2
Block of statements
break
default
default statements
Statement N
E print Entera
Scant Id a
switch a
cases
printfl TK
break
case
printf Name
break
default
print Bye
print Go to home
a 2 Enter a b
Engine
Go to home
Go to home
EI printf Enter a
a
scant fd
switch 12
24 By default takes the argument
as mandancogresponds
case 5 print JK
break
case 4 print Hehe
break
default
print Bye
OII Hehe
Bye
Flowchart 1
Expression
Tisegualtered
Casevaluef
yeah
f
no
wdfak
Ésffdt
No i
1
Treating
Handoff statement
C program for a
simple calculator
include station
include conio.us
void mains
scarf 1 c operator
Enter two operands
print
1 did Ia Ib
scarf
Switch operator
case mhd a b
mul I d mel
print
case 851 a b
div f d dir
printf
break
default print Enter valid operator
getchel
Loops in C
For loops
11 loop body
Es for i 1 9 10 itt
print E t.dk i
01
I
first i initialized there is a space in the
is
memory for i and its now filled with 1 Now
Now it holds hence it goes to
it checks if i 2 10
Flowchart
Initializations
false A
Lafon
Bodyofloopf
I
true
modifylupdated
11Body of loop
FI void main
int i
for i i2 5 it t
printf t.dk i
geth
3
You can initialize the variable
It void main
outside the for loop and
int i 1 leave the initialization
for ic 5 it t part of the for
i
he ends
T.tt dim i
geth
3
void main initialize anywhere
when we don't
it will not give
int any
for i ic 5 itt output
printf t.dk i
geth
3
when we have to initialise two variables at
the same time we enclose them separated
comma
by a
include Lstdio.us
include conions
int i
for i 0 ices itt
print Id Id In i j
getche
print Id Id In i j
getche
include stdio.us
I
include conions
inti
for 1 1 1 0 1 5,143 itt
print Id Id In i j
getche
Note when we
give multiple conditions then the
last is treated as the termination statement
statement
i e the loop terminates only after the last statement
is completely executed
OP 1 0 Forms an infinite loop as
2 0 the termination condition is
1 0 which is always true
3,0 the condition termination is
of
not getting updated here
C
program
to print table of a number
include cstdio.hn
include cconio.us
void main
for i 1 10 itt
r a
print ati I.dk 0
getchell
4
6
8
20
while loop
syntax initialization
while condition
statement 1
statement n
update modify
Ehrhart Initializations
false fonditiont
find
statementfBo
modify
C
program
to print table of a number
using whileloop
include cstdio.us
include conions
void main
int i t
while 10
printf Id in i
Itt
getchi
EI void mainll
int i 1 considered
boolean 1
while i 10 as
True
fd i
print
tti
End of Program
print note when we use
getchC
while 1 it means
it always true condits
IP a loop
Do while Loop
for and while loop are entry control loop but dowhile
loop is exit control loop
Syntax Initialization
do
statements
modify update
while condition
statement
Incrementlemment
t
True Condition
false
t
without ducking anything control enters the loop then
condition is checked if it satisfies again it runs back
the loop but if its not satisfied it goes out the
loop
But atleast one time the loop body is executed
Difference between for while do while loop in C
break statement in C
for i is 5 itt
if azo
break
sum sum a
printf Id sum
a i sum
0P Enter a number I
Enter a number 4 D
Enter a number 7 12
Enter a number I IF
break
As If the condition is
changed as
The he she
user can enter as many number
wishes but when he inputs a negative number the
loop breaks The program looks like
include stdio h
include conio h's
void main11
int a sum O
while s
scarf Id a
if aco
break
Sum Sum a
Continue statement in
C when we use continue
statement
the control does not flow to the next statements
down but it
goes back increment decrement update
section of the loop
the flow goes to update section and makes the loop run
again
for initialization condition update
statement
statement z f condition satisfied
conditin
if condition
if
not continue Does not get
statement 3
satisfy Statement 4
executed
statement R
3
false loop
condition
true update
condition true
continue
false
v
includesstdio.hr
include conio h
void main
int i a sum 0
for i L 1 5 itt
for 1 1 1 6 Itt
FI IIEE
for i 1 1 5 it
printfe
p nt In
False outer
loopondition
True
False Inner
loopondition
Outerloop
SB true