Upload
atul-galande
View
226
Download
0
Embed Size (px)
Citation preview
7/24/2019 C Language Basic Question
1/64
Da
1 Draw th
Compute
1)
2) I
3)
4)
1)
IN(Mous
rshan Inst
e block dia
r is made up
entral proce
nput section
utput sectio
torage devic
entral Proc
Central pr
It contain
It also co
It is also
CPU consi
.1) Arith
It
It
It
Itm
.2) Contr
It
It
It
.3) Prima
It
T
UT SECTIO, Keyboard, e
itute of En
Computer
ram of co
f mainly four
sing unit (CP
s
ssing Unit (
ocessing unit
electronics
trols the flo
nown as brai
sts of,
etic Logic U
performs all
can perform
calculates ve
takes dataemory.
ol Unit (CU)
controls all o
manages all
reads instru
ry Memory:-
is also know
e processor
Ntc...)
gineering
Programmi
A) Co
puter arch
components,
)
CPU):-
is a main par
ircuitry that
of data in th
n of the com
it (ALU)
arithmetic cal
add, subtract
ry fast.
from memor
ther units in
operations
tion and data
as main me
r the CPU di
Cen
SE
(Har
PR
& Technol
1
ng and Util
mputer Fu
itecture an
t of the comp
rocesses the
e system.
uter.
lculations and
, multiply, co
y unit and r
he computer
from memor
mory.
ectly stores
ral Processi
ONDARY M
disk, Pen dri
ALU + C
IMARY ME
RAM, ROM, et
ogy
ization (CP
damentals
explain ea
uter system.
data based o
takes logical
mpare, count
eturns data
system.
y.
nd retrieves i
ng Unit
EMORY
ve, etc)
ORY
c)
) 11000
ch block.
n instructions
decision.
, shift and ot
o memory u
information fr
(
yllabus for 1
.
er logical act
nit, generall
om it.
OUTPUT SE
Monitor, Print
stmidsem ex
ivities.
primary
CTION
er, etc)
m
7/24/2019 C Language Basic Question
2/64
7/24/2019 C Language Basic Question
3/64
Da
s
s
c
Limitati
t
t
3 Describ
Compute
1)
2)
3)
rshan Inst
ame form. It
utomation:
ingle click w
omputer, it c
ns
ake of intel
hink about p
hink about th
nable to Co
r incorrect d
various ty
r languages
Machine le
Compute
has its o
ADVANT
1.
It is
2. It do
3. Tran
4. Suit
DISADV
1. Prog
2. Deb
3. It is
4.
Prog
Assembly la
Every m
describe
System
language
Example
ADVANT
1. Prog
2. Prog
3.
Prog
DISADV
1. It is
2. Prog
3. It re
Higher level
We can
Program
itute of En
works 24 ho
Once the on
enever we w
omputes the i
igence: It c
operness or
e correctness
rrect Mista
ta then it pro
pes of com
ay be classifi
el language
r directly un
n machine l
GES:
very fast in e
es not requir
slation is not
ble for low v
NTAGES:
rams are long
gging is very
not portable.
rammer requi
nguage:-
chine langu
function of in
annot under
to machine l
: 8086 Instru
GES:
rams are eas
rams are sma
rams can be
NTAGES:
not portable.
rammer shoul
uires assem
language:-
rite program
er can perfo
gineering
rs without an
e task is cre
ant. For exa
nterest by se
nnot think w
ffect of wor
of these inst
es: It canno
duces wrong
uter langu
ed in three c
or Low lev
erstands this
nguage.
ecution
any extra sy
required.
lume applica
and difficult
difficult task.
res detailed k
ge instructio
struction.
tand this lan
anguage. Thi
ction Set
to understa
ller in size co
ntered quickl
ld know struc
ler as a tran
s in English li
rm complex t
& Technol
3
y problem as
ted in a co
ple, once th
nding one co
ile doing wo
it is doing.
uctions.
correct the
results or pe
ages and m
tegories,
l language:
language. It
stem or soft
ions.
to write and
.
nowledge of
n is assigned
guage directl
translator is
d compared
mpared to m
y using alpha
ure of assem
lator.
e manner an
ask by using
ogy
it does not f
puter, it can
software for
mand.
k. It does no
t can only e
mistakes by i
forms wrong
ention its a
is a languag
are to run th
nderstand fo
architecture o
to English
y so we requi
called assem
o machine le
chine level l
numeric keyb
bly language
d it is more c
high level lan
el tiredness.
be repeated
banking app
have natura
ecute the in
tself. So if w
calculations.
dvantages
of 0s and
e program.
r human.
f microproce
ord MNEMO
ire translator
bler.
vel language.
nguage.
oard.
of microproc
onvenient to
guages with l
yllabus for 1
ly performed
lication is ins
l intelligence.
tructions but
have provid
nd disadva
s (binary).
sor.
IC such that
that convert
ssor.
use.
ess efforts.
stmidsem ex
again by
alled in a
It cannot
it cannot
ed wrong
ntages.
very CPU
it should
assembly
m
7/24/2019 C Language Basic Question
4/64
Da
4 Why C i
C is calle
I
I
I
5 Write a
A set of i
called sof
System
System s
for runni
"low-leve
System s
1)
t
2)
I
3)
Applicat
Applicati
some sp
suites, G
Applicati
1)
rshan Inst
It is simil
Example:
ADVANT
1) Easi
2)
Req
3) Provi
4) Easi
5) It is
DISADV
1) It re
2) Prog
3)
It is
called mid
middle level
yntax and k
t gives advan
t gives acces
oreover it d
e can devel
ssembly leve
t is not hard
short note
instruction in
tware.
oftware
oftware is de
g applicatio
l" software.
oftware can
perating sys
o user. It is a
ystem suppo
/O devices or
ystem develx: Editor, pr
ion softwar
n software is
cific task (a
aphics softw
n software is
eneral purp
rocessing, w
itute of En
lar to natural
: C, C++, Jav
GES:
r to learn.
ires less time
ides better do
r to maintain
portable.
NTAGES:
uires compil
rammers nee
bit slow comp
dle level la
language be
ywords of C
tages of high
to the low le
es support th
op applicatio
l language to
are or syste
n types of
a logical ord
igned to ope
software. Si
e classified in
em: It contr
bridge betw
rt software:
routine for s
pment softw-processor, c
designed to
counting, tic
re and medi
classified int
se software:
b browser, e
gineering
language and
a, etc
to write.
cumentation.
.
r or interpre
to learn str
ared to low l
guage?
ause
re just like hi
r level langu
vel memory
e Low Level
n specific pr
give more sp
dependent.
software.
r to perform
ate the com
nce system
to three cate
ls hardware
en computer
It makes wor
cket progra
are: It proviompiler, inter
elp the user
et booking
players.
two categor
It is used
xcel, etc It i
& Technol
4
mathematic
er to convert
cture of high
vel and medi
igher level la
age through f
hrough Point
rogramming
grams in C
eed and effici
Hence porta
a meaningf
uter hardwar
oftware runs
gories
as well as int
hardware an
king of hard
ming, etc
es programpreter, loade
to perform g
). Example:
ies.
widely by m
s designed o
ogy
l notation.
higher level l
level langua
um level lang
guage (Engli
unction, mod
rs.
i.e., Assembl
and at the
ency
le programs
l task is call
e efficiently.
at the most
eracts with u
user. Ex: Wi
are more ef
ing developr, etc..
neral tasks (
Enterprise s
any people
vast concep
anguage to
e.
uage.
h).
ular program
Language.
ame time w
an be writte
d program a
t provides an
basic level o
ers, and pro
indows XP, Li
iciently. For
ent environ
word processi
ftware, Acco
or some co
so many pe
yllabus for 1
achine langu
ing and bre
e can use f
with C com
nd a set of p
d maintains
computer, i
vides differen
ux, UNIX, et
example driv
ent to prog
ing, web bro
unting softw
mon task,
ple can use i
stmidsem ex
age.
kup.
atures of
iler.
rogram is
platform
is called
t services
c
rs of the
rammers.
ser ) or
re, Office
like word
.
m
7/24/2019 C Language Basic Question
5/64
Da
2)
t
s
6 Define t
1.
2.
3.
4.
5.
6.
I
t
7. I
I
rshan Inst
pecial purpo
ax calculatio
pecial requir
he followin
rogram
set of instru
oftware
set of instr
rogram is cal
ardware
hysical parts
perating sy
perating sys
rovides inter
ssembler
ssembler is s
ompiler
t translates
ime.
nterpreter
t translates p
itute of En
e software: I
software, ti
ment.
g terms:
ction in a logi
uction in a l
led software.
of computer i
stem
em is system
ctive platfor
ystem softwa
rograms of h
rograms of hi
gineering
t is used by
ket booking
cal order to p
ogical order
s known as H
software whi
to user.
re which con
igher level la
gher level lan
& Technol
5
limited peopl
software, ba
erform a me
to perform a
ardware. Use
ich works as
erts program
nguage to m
guage to ma
ogy
for some sp
nking softwar
ningful task i
meaningful
r can see and
n interface b
s of assembl
achine langu
hine languag
ecific task lik
e etc It is
s called progr
task is calle
touch the ha
etween hard
language to
ge. It conver
e. It converts
yllabus for 1
e accounting
designed as
am.
program, a
rdware comp
are and user
machine lan
ts whole pro
program line
stmidsem ex
software,
er users
nd set of
onents.
and
uage.
ram at a
by line.
m
7/24/2019 C Language Basic Question
6/64
1
Dars
What is
them.
Flowchar
Flowch
differe
togeth
solutio
Advan
Ea
Ea
Ea
Ea
Disad
Ti
Di
Ve
Algorithm
An Alg
in the
Advan
Ea
H
Al
Disad
Di
Di
Ju
Comparis
Flowcha
It is a pic
Solution i
Easy to u
Easy to s
Flowchar
an Institu
C
lgorithm?
art is a picto
nt symbol a
er with arro
n of the give
tages
sy to draw.
sy to underst
sy to identify
sy to show br
antages
e consumin
ficult to modi
ry difficult to
orithm is a fi
natural langu
tages
sy to write.
man readabl
orithms for
antages
ficult to debu
ficult to sho
mping (goto)
n:
rt
orial represe
s shown in gr
nderstand as
ow branchin
for big probl
te of Engi
mputer Pr
hat is Flo
rial or graphi
d contains
s showing t
problem.
and logic.
mistakes by
anching and l
.
fy.
draw flowcha
ite sequence
ges like Engl
techniques
ig problems
g.
branching a
makes it har
ntation of a p
aphical forma
compared to
and looping
m is impract
eering &
gramming
B) Flowc
chart? Wri
cal represent
short descr
e process fl
non compute
ooping.
rt for big or c
of well defin
ish.
o understand
an be writte
d looping.
to trace so
rocess.
t.
algorithm.
.
ical
Technolog
and Utiliza
art & Algo
te down th
ation of a pr
iption of the
w direction.
person.
omplex probl
d steps for s
logic.
with modera
e problems.
Algorithm
It is step w
Solution is
It is some
Difficult to
Algorithm
y
ion (CPU)
ithm
advantage
cess. Each s
process ste
This pictorial
ms.
lving a probl
te efforts.
ise analysis o
shown in non
hat difficult t
show branchi
an be writte
Syll
110003
s and disad
ep in the pr
. The flow
representati
em in system
f the work to
computer la
o understand
ng and loopin
for any prob
abus for 1st
vantages.
cess is repre
hart symbol
n can give
atic manner.
be done.
guage like E
.
g.
lem
idsem exam
ompare
sented by a
are linked
tep-by-step
It is written
glish.
7/24/2019 C Language Basic Question
7/64
2
W
3
Dars
Explain v
ite an alg
To find w
Algorithm
Step 1 :
Step 2 :
Step 3 :
Step 4 :
Step 5 :
Flowchar
an Institu
arious sym
rithm an
ether given
:-
Input no.
If no mod
Print give
Print give
Stop.
:-
te of Engi
ol used in
Draw a fl
number is
2=0, goto 4.
no is odd, g
no is even.
Print no
eering &
lowchart.
owchart
ven or odd.
to 5.
is Even
Yes
Technolog
Start /
Input /
(Read
Proces
Decisi
Subro
Arrows
st
R
Is No
y
Stop
Output
/ Print)
s
n making
tine
op
start
ead No
mod 2=0?
Syll
Pri
abus for 1st
No
nt no is Odd
idsem exam
7/24/2019 C Language Basic Question
8/64
4
Dars
To enter
negative
Algorithm
Flowchar
Step 1 :
Step 2 :
Step 3 :
Step 4 :
Step 5 :
Step 6 :
Step 7 :
Step 8 :
Step 9 :
Step 10 :
Step 11 :
Step 12:
an Institu
umber still
nd zero ent
:-
:-
Initialize p
Read no
If no>0, g
If no0?
0,zero0
neg+1
stop
y
display cou
No
No
nt toe no?
g, zero
Is no
7/24/2019 C Language Basic Question
9/64
5
Dars
To print
Algorithm
Step 1 :
Step 2 :
Step 3 :
Step 4 :
Step 5 :
Step 6 :
Step 7 :
Step 8 :
Step 9 :
Flowchar
Prin
an Institu
aximum nu
:-
Read a ,b,
If a>b, go
If b>c, go
Print c is
If a>c, go
Print c is
Print a is
Print b is
Stop.
:-
Yes
t max = a
te of Engi
mber from a
c
to 5
o 8
aximum got
o 7.
aximum, go
aximum, go
aximum
Yes
Isa>c?
P
eering &
given 3 nu
9
o 9
o 9
rint max =
No
Technolog
bers.
Read a, b, c
Isa > b?
c
start
stop
y
Print max
Yes
No
Syll
Isb>c?
= b
abus for 1st
Print m
No
idsem exam
x= c
7/24/2019 C Language Basic Question
10/64
6
Dars
To find th
Algorithm
Flowchar
Step 1 :
Step 2 :
Step 3 :
Step 4 :
Step 5 :
Step 6 :
Step 7 :
an Institu
e factorial o
:-
:-
Initialize c
Read no
Calculate f
Increment
If countb)?a
>b)
x=a;
x=b;
wise Operat
ise operator
ouble.
bitwis
bitwis
bitwis
shift l
shift ri
cial Operat
Addre
Point
Com
zeof It ret
mem
mem
conditiona
rovides speci
itute of En
s value of ri
1 is same as
is same as
1 is same as
is same as
1 is same a
Decrement
l operators in
ents value b
s postfix, the
10; b=a++;
s prefix, the v
10; b=++a;
ments value
postfix, the e10; b=a--; a
prefix, the va
10; b=--a; a
erator
or is known a
if exp1 is tru
:b; which is s
ors
s are used to
AND
OR
exclusive O
ft ( shift left
ght ( shift rig
ors
ss operator, i
r operator, it
a operator. I
rns the num
er selection
er selection
l operator (t
al conditional
gineering
ht side to lef
a = a + 1
a = a - 1
a = a * 1
a = a / 1
a = a % 1
Operators
C which are
y 1.
expression is
after this sta
alue is incre
after this sta
y 1.
xpression is efter this stat
lue is decrem
fter this stat
s Conditional
e then execu
ame as
perform oper
eans multip
ht means divi
t is used to d
is used to de
t is used to li
er of bytes t
perator, use
perator, use
ernary oper
operator ( ? :
& Technol
6
side
generally not
evaluated fir
ement, a= 1
ented first a
ement, a= 1
valuated firstment, a= 9,
ented first an
ment, a= 9,
Operator.
e exp2 other
ation bit by bi
ly by 2)
de by 2)
etermine add
clare pointer
k the relate
e operand o
in structure.
in pointer t
ator) with e
) to evaluat
ogy
found in othe
t and then t
1, b = 10.
nd then the e
1, b = 11.
and then theb = 10.
d then the ex
b = 9.
ise exp3
it. Bitwise op
ess of the va
variable and
expressions
cupies.
.
structure.
xample.
conditional
r languages.
e value is inc
xpression is e
value is decr
pression is e
rators may n
riable.
o get value f
together.
xpression in
yllabus for 1
remented.
valuated.
emented.
aluated.
ot be applied
om it.
single line.
stmidsem ex
to float
m
7/24/2019 C Language Basic Question
18/64
Da
It i
or
Sy
Fir
ex
Ex
9 What i
Wh
as
Ty
Implici
Explici
Exampl
rshan Inst
s also known
xpressions.
tax: expr1?
t of all expr
r3 is evaluat
mple: c = a>
s type conv
en an operat
ype casting
ecasting is m
t Type Casti
C automatic
evaluated wi
This automa
The lower ty
result is hig
Example:
o If o
o If o
Thus conver
conversion
Type Casti
Sometimes
The process
The general
Where type-
an expressi
e:
#include
short
ConversionHierarchy
gineering
erator becau
pr3
, if it is non
f expr2 and
a is greater
in implicit
ds of differen
sion.
ble of one da
ny intermedi
ny significan
is known as
ically conver
int and other
float and oth
from low dat
own below.
ce a type co
l conversion
s: (type
f the standa
unsi
int
char
& Technol
7
se this is the
zero (true) t
xpr3 is evalu
than b then a
nd explicit
types, they
a type to act
ate values to
e.
implicit type
ed to the hig
is float then
er is long dou
type to high
version in a
or casting is
-name) expre
d C data typ
unsigned
long int
gned int
ogy
only operator
en the expr
ated.
is assigned t
ype convers
are converted
like another
the proper ty
conversion.
her type befo
int will be co
ble then float
data type so
ay that is di
nown as expl
ssion.
. The expres
long int
float
doubl
lon
in C which r
ssion expr2
o c otherwise
ion with ex
to a commo
ata type suc
pe so that th
e the operati
verted to flo
will be conve
that informa
ferent from
licit casting.
ion may be c
double
yllabus for 1
equires three
is evaluated
b.
mple.
type, this is
as an int to
expression
on proceeds.
t.
rted to long
ion is not los
utomatic con
onstant, vari
stmidsem ex
operands
otherwise
known
float.
an be
The
ouble.
. The
version.
ble, or
m
7/24/2019 C Language Basic Question
19/64
Da
10 Explai
Pre
Op
(5
We
op
Ass
sa
Op
8 -
We
firs
mu
Foll
Ra
Prece
1
2
3
4
5
6
rshan Inst
void main()
{
int
floa
avg
prin
avg
prin
}
operator p
cedence of a
rator preced
3) * 2, givi
say that the
rator (+), so
ociativity is t
e precedenc
rator associ
(3 - 2), givin
say that the
t. When we c
st use associ
owing table
k 1 indicates
dence As
Le
Ri
Le
Le
Le
Le
itute of En
um=47, n=1
avg;
sum / n;
tf(Result of I
(float)sum /
tf(Result of
recedence a
operator is i
ence is why t
g 16.
multiplication
the multiplic
e left-to-righ
e.
tivity is why
g 7.
subtraction o
an't decide by
tivity.
rovides a co
highest prec
sociativity
t to Right
ht to Left
t to Right
t to Right
t to Right
t to Right
gineering
0;
mplicit Type
(float)n;
xplicit Type
nd associati
s priority in
e expression
operator (*)
tion must be
t or right-to-l
he expressio
erator (-) is
operator pre
plete list of
dance level
Operat
()
[]
+, -
++, --
!
~
*
&
sizeof
(type)
*
/
%
+
-
>
=70)
pr i nt f
se i f ( avg>
pr i nt f
se i f ( avg>
pr i nt f
se i f ( avg>
pr i nt f
se
pr i nt f
with examp
ecisions are i
n-1is true th
n Statement-
n-1is false t
i t i on- 1)
est- condi t i
St at ement
St at ement
ment - 3;
gineering
nt based on
, m4, m5;
r m1, m2, m3,
%d%d" , &m
3+m4+m5) / 5;
( Di st i nct
=60)
( "F i r s t cl
=50)
( "Second c
=40)
( "Pass cl a
( " f ai l " ) ;
le and draw
volved, we
en test-condi
2will be exe
en Statemen
on- 2)
-1 ;
-2 ;
& Technol
4
verage mark
m4, m5: ") ;
, &m2, &m3,
) ;
ass") ;
l ass" ) ;
s s " ) ;
flowchart.
ay have to u
tion-2is eval
uted.
t-3will be ex
ogy
s.
, &m4, &m5)
se more than
ated. If it is
ecuted.
;
one ifelse s
rue then Sta
yllabus for 1
tatement in
ement-1will
stmidsem ex
ested form
be executed,
m
7/24/2019 C Language Basic Question
25/64
Da
Flow
Exam
S
rshan Inst
hart:
ple: Find ma
#i ncl ude
voi d mai
{
i p
s
i f
{
}
e
{
}
}
False
atement-3
itute of En
imum numb
n()
t a, b, c;i nt f ( "Ente
anf ( "%d%d%
( a>b)
i f ( a>
el se
se
i f ( b>
el se
Cond
gineering
r from given
r val ue of
d", &a, &b,
)
pr i nt f ( "a
pr i nt f ( "c
)pr i nt f ( "b
pr i nt f ( "c
Entry
estition 1?
& Technol
5
three numbe
a, b, c: " ) ;
&c);
i s max") ;
i s max") ;
i s max") ;
i s max") ;
True
True
TCondi
State
Next st
State
ogy
s.
;
sttion 2?
ent-1
atement
ent-x
False
yllabus for 1
tatement-2
stmidsem ex m
7/24/2019 C Language Basic Question
26/64
Da
5 Expl
T
I
e
E
I
I
T
Exam
rshan Inst
in switch-c
he switch sta
tests wheth
eneral formswi t ch( e
{
c
c
c
d
}
xpressionin
ach case is la
a case matc
alue of all ca
none of the
he break stat
ple:
swi t ch (
{
c
c
c
c
c
d
}
itute of En
se stateme
tement is a m
r an expressi
f switch-casxpr essi on)
se const - e
se const - e
se const - e
f aul t :
state
witch should
beled by one
hes the expre
e expression
cases are ma
ement cause
grade)
se 1:
pr i nt f
break;
se 2:
pr i nt f
break;
se 3:
pr i nt f
break;
se 4:
pr i nt
break;
se 5:pr i nt f
break;
f aul t :
pr i nt f
break;
gineering
nt with exa
ulti-way deci
on matches
is as below,
xpr 1: st
br
xpr 2: st
br
xpr 3: st
br
ent s
be integer or
or more inte
ssion value t
s must be diff
ched then de
an immedia
( "Fal l ( F )
( "Bad ( D) \
( "Good ( C)
( "Very Goo
( "Excel l en
( "You have
/ /
& Technol
6
ple.
sion making.
ny one of th
t ement 1;
ak;
t ement 2;
ak;
t ement 3;
ak;
character ex
er-valued co
en execution
erent.
fault case is
e exit from t
\ n " ) ;
n" ) ;
\ n " ) ;
d ( B) \ n") ;
t ( A) \ n") ;
i nput t ed f
br eak i sn t
ogy
constant val
ression. Floa
nstant.
starts at tha
xecuted. def
e switch.
al se gr ade
necessary
ues or not.
t or any othe
case.
ult case is o
n" ) ;
her e
yllabus for 1
r data type is
tional.
stmidsem ex
not allowed.
m
7/24/2019 C Language Basic Question
27/64
Da
Rules
6 Stat
If
al
If
If
Fl
b
Write a C Pr
1 Find
#i ncl
voi d
{
}
2 Find
#i ncl
voi d
{
rshan Inst
for switch st
The switc
Case label
Case label
Case label
The break
The defaul
Nesting of
difference
statement is
ernatives.
can have val
implements
at, double, c
used in if co
ogram to.
out whethe
l ude
ent er no: ")
d", &no);
=0)
i nt f ( "no i
i nt f ( "no i
umber from
h>
c;
ent er a, b, c
d%d%d" , &a,
gineering
ust be integ
stant or con
que.
ith colons.
optional.
ent is option
ent is allow
lse and swi
among two
constraints.
ther data typ
umber is od
;
s even") ;
s odd") ;
given 3 nu
: " ) ;
b, &c);
& Technol
7
al type. Floa
tant expressi
l.
d.
ch-case
Th
mul
Swi
Swi
es can Onl
blo
d or even.
bers.
ogy
or other dat
on.
switchstate
ltiple alternati
tchcan have
tchimplemen
y int and cha
k.
types are n
switch
ent is used
ves.
values based
ts Binary sea
data types c
yllabus for 1
t allowed.
o select amo
on user choi
rch.
an be used in
stmidsem ex
ng
e.
switch
m
7/24/2019 C Language Basic Question
28/64
Da
}
3 whic
#i ncl
voi d
{
}
rshan Inst
i f ( a>b&&
p
el se i f (
p
el se
p
h asks day
l udec)
i nt f ( " a i s
b>c)
i nt f ( " b i s
i nt f ( " c i s
umber and
h>
ent er day
d", &day) ;
ay)
se 1:
pr i nt f
break;
se 2:
pr i nt f
break;
se 3:
pr i nt f
break;
se 4:
pr i nt f
break;
se 5:
pr i nt f
break;
se 6:
pr i nt
break;
se 7:pr i nt f
break;
f aul t :
pr i nt f
gineering
maxi mum") ;
maxi mum") ;
maxi mum") ;
prints corre
umber ( 1- 7
( "sunday")
( "monday")
( " t uesday"
( "wednesda
( "t hur sday
( " f r i day")
( "saturday
( "wr ong i n
& Technol
8
ponding da
\ n" ) ;
;
;
) ;
y " ) ;
" ) ;
;
" ) ;
put" ) ;
ogy
y name usin
g switch-ca
yllabus for 1
e.
stmidsem ex m
7/24/2019 C Language Basic Question
29/64
Darshan Institute of Engineering & Technology Syllabus for 1stmidsem exa
1
Computer Programming and Utilization (CPU) 110003
E) Loop Control Structure (for, while, dowhile)
1 Explain loops available in C with example
Loops are used to repeat execution of a block of code.
During looping, a set of statements are executed until some condition for termination is encountered.
Generally, looping process would include the following four steps
1) Initialization of a counter
2) Test for a termination condition
3) Loop body statements
4) Increment the counter
C supports three types of looping
while loop
The simplest of all looping structure is while statement.
The general format of the while statement is:
I ni t i al i zat i on;
whi l e ( t est condi t i on)
{
body of t he l oop ;
i ncrement or decr ement ;
}
Test condi t i onis evaluated and if the condition is true then the body of the loop is executed.
After the execution of the body, the t est condi t i onis once again evaluated and if it is true, the body
is executed once again.
This process is repeated till the t est condi t i on is true. When it becomes false, the control is
transferred out of the loop.
On exit, the program continues with the statements immediately after the body of the loop.
While loop is also known as entry control loop because first control-statement is executed and if it is true
then only body of the loop will be executed.
Exampl e: To pr i nt f i r st 10 posi t i ve i nt eger numbers
voi d mai n( )
{
i nt i ;
i = 1; \ \ i ni t i al i zat i on of i
whi l e(i
7/24/2019 C Language Basic Question
30/64
Darshan Institute of Engineering & Technology Syllabus for 1stmidsem exa
2
dowhile loop
In contrast to while loop, the body of the dowhile loop is executed first and then the loop condition is
checked.
The body of the loop is executed at least once because dowhile loop tests condition at the bottom of
the loop after executing the body.
dowhile loop is also known as exit control loop because first body statements are executed and then
control-statement is executed, thus condition checking happens at exit point.
The general format of the dowhile statement is:
i ni t i al i zat i on;
do
{
st atement ;
i ncrement or decr ement ;
}
whi l e( t est- condi t i on) ;
Exampl e: To pr i nt f i r st 10 posi t i ve i nt eger number s
voi d mai n( )
{
i nt i ;
i = 1; \ \ i ni t i al i zat i on of i
do
{
pr i nt f ( \ t %d, i ) ; \ \ st at ement execut i on
i ++; \ \ i ncrement of cont r ol var i abl e
} whi l e(i
7/24/2019 C Language Basic Question
31/64
Darshan Institute of Engineering & Technology Syllabus for 1stmidsem exa
3
Exampl e: / / The f ol l owi ng i s an exampl e t hat f i nds t he sum of t he f i r st t en posi t i ve
i nteger number s
voi d mai n( )
{
i nt i ; / / decl are var i abl e
i nt sum=0;
f or ( i =1; i < = 10; i ++) / / f or l oop
{
sum = sum + i ; / / add t he val ue of i and st or e i t t o sum
}
pr i nt f ( %d, sum) ;
}
We can include multiple expressions in any of the fields of for loop provided that we separate such
expressions by commas. For example: for( i = 0; j = 100; i < 10 && j>50; i++, j=j-10)
f or Loop whi l e Loop dowhi l e Loop
f or( i =1; i < = 10; i ++)
{
sum = sum + i ;
}
i =1;
whi l e( i
7/24/2019 C Language Basic Question
32/64
7/24/2019 C Language Basic Question
33/64
1
Dar
What i
An
An
Th
Th
Syntax
Exampl
Th
Th
In
Advan
Yo
An
An
Examp
Types1) Sin
2) Tw
3) Mul
han Insti
s an array?
array is a fix
array is deriv
individual el
subscript fo
: dat
e : i nt
data_types
sizeindicate
he example,
ages:
can use one
array is very
array makes
le:
#i ncl ude)
a[ 5] = {5,
i =0; i
7/24/2019 C Language Basic Question
34/64
2
Dar
Explai
Single
An arra
Syntax
Exampl
An
g =
Mo
will
We
sig
Th
an
For
var
for
Ab
ad
tot
Th
up
Initiali
The ge
There a
1. i nt
will
2. i nt
will
3. i nt
firs
ele
han Insti
initializati
Dimensiona
y using only
: dat
e : i nt
individual arr
marks [60];
e generally
take the val
can store val
like marks[
ability to re
efficient pro
example we
iable that is
i=0; i
7/24/2019 C Language Basic Question
35/64
3
Dar
Two di
Tw
Tw
Firs
Syntax
Exampl
He
thr
A t
35.
Initiali
1.
i nt
will
col
2. i nt
her
col
3. i nt
init
Explai
C has s
For Exa
Funct
strlen
strcm
han Insti
mensional a
dimensional
dimensional
t subscript d
: dat
e : i nt
e m is decla
ugh 19). Th
o dimension
5 & second el
mar
35.
mar
66.
mar
85.
mar
25.
zation of tw
t abl e[ 2] [
initialize 1st
mn to 6 and
t abl e[ 2] [
e, 1stgroup i
mn element
t abl e[ 2] [
ializes as abo
various str
everal inbuilt
mple: char s
ion
s1)
(s1,s2)
ute of Eng
rrays:
arrays are al
arrays have
notes the nu
a_t ype arr a
marks[ 10] [
ed as a mat
first elemen
al array mark
ement is mar
ks [0][0]
ks [1][0]
ks [2][0]
ks [3][0]
o dimension
3] = {1, 2, 3
ow 1stcolum
so on.
3] = {{1, 2,
for 1strow a
is 4, 2ndrow
3] ={{1, 2},
ve but missin
ing handlin
functions to
[]=Their, s
Returns le
l = strlen(s
Compares
It returns
ineering
so called tabl
wo subscript
ber of rows
y_name[ r ow
20] ;
ix having 10
of the matri
s[4][3] is sh
ks[0][1] and
mark
40.5
mark
55.5
mark
78.5
mark
35.2
al array:
, 4, 5, 6};
element to
3}, {4, 5, 6}
nd 2ndgroup
rdcolumn el
{4}}
g elements w
operations
perate on str
2[]=There;
gth of the st
1); it returns
two strings.
egative valu
Technolo
3
or matrix.
.
and second s
s i ze] [ col u
rows (numb
is m[0][0]
wn below. T
contains 40.5
[0][1]
[1][1]
[2][1]
[3][1]
, 1strow 2nd
;
is for 2ndrow.
ment is 6 so
ill be initialize
available in
ing. These fu
ing.
5
if s1s
S
tes the numb
o 9) and 20
w last colum
nt is given b
][2]
][2]
][2]
][2]
1strow 3rdcol
tcolumn ele
mple.
own as strin
and zero if
llabus for 1st
er of columns
columns (nu
is m[9][19]
marks[0][0]
umn to 3, 2nd
ent is 1, 2nd
handling fu
1=s2.
midsem exa
.
bered 0
contains
row 3rd
row 1st
ctions.
7/24/2019 C Language Basic Question
36/64
Dar
strcpy
strcat
strchr
strstr(
strrev
strlwr
strupr
strncp
strnca
strnc
strrch
han Insti
(s1,s2)
s1,s2)
(s1,c)
s1,s2)
(s1)
s1)
(s1)
y(s1,s2,n)
t(s1,s2,n)
p(s1,s2,n)
r(s1,c)
ute of Eng
printf(%d
Output : -
Copies 2nd
strcpy(s1,s
s2 remains
Appends 2n
strcat(s1,s
becomes
Returns a
printf(%s
Output : ir
Returns a
printf(%s
Output : h
Reverses g
strrev(s1);
Converts s
printf(%s
Converts s
printf(%s
Copies firs
s1=; s2=
strncpy(s1,
printf(%s
Output : T
Appends fi
strncat(s1,
printf(%s
Output : T
Compares
strcmp() f
printf(%d
Output : 0
Returns th
printf(%s
Output : e
ineering
, strcmp(s1,
string to 1sts
2) copies the
unchanged.
dstring at th
); a copy o
heirThere
ointer to the
,strchr(s1,i)
ointer to the
,strstr(s1,h
ir
iven string.
makes string
ring s1 to lo
, strlwr(s1));
ring s1 to up
, strupr(s1));
n character
There;
s2,2);
,s1);
st n characte
s2,2);
, s1);
eirTh
first n chara
nction.
, strcmp(s1,
last occurre
,strrchr(s2,e
e
Technolo
4
2));
tring.
string s2 in t
end of 1stst
string s2 is
first occurre
);
first occurre
));
s1 to riehT
er case.
Out
per case.
Out
f string s2 t
r of string s2
cter of strin
2,3));
nce of a give
));
gy
o string s1 so
ring.
appended at
ce of a given
ce of a given
ut : their
ut : THEIR
string s1
at the end of
s1 and s2
character in
S
s1 is now T
the end of
character in
string s2 in s
string s1.
and returns
a string s1.
llabus for 1st
ere.
tring s1. No
he string s1.
tring s1.
similar resu
midsem exa
s1
lt as
7/24/2019 C Language Basic Question
37/64
Da
1 What
A
T
T
T
It
P
It
f
While
1
2
rshan Ins
is user defi
function is a
he functions
he functions
he functions
has a uniqu
rameter or a
is optional t
nction, their
using functio
.
Function D
Like v
The fu
four p
1
2
3
4
Synta
Examp
In this
functio
. Function D
Functi
It has
Fu
Fu
.
Function
Functi
Functi
enclos
itute of En
Comput
ned functio
block of code
hich are cre
hich are in-b
hich are imp
name and it
rgument pas
o return a v
return type is
n, three thing
eclaration
riables, all th
nction declar
rts,
) Function t
) Function n
) Parameter
)
Terminatin
: Fu
m( i nt , i n
ction return t
e integer.
s also called
rts.
: It is same
: It is actual
from main fu
led by simpl
eses.
& Technol
1
ing and Ut
G) Functi
ith example
s a specific ta
mmer are ca
r are known
eader librari
. it can be c
n is optional.
lling progra
nt
ust be declar
nown as fun
pe).
ct i onName
) ;
ype is int, na
unction impl
as function d
logic or codi
ction or oth
using a fun
ogy
ilization (C
ns
. Define the
sk.
lled user-defi
as system fu
s are known
lled from an
. Function w
ed before the
tion prototyp
( Argument 1,
me of functio
mentation.
claration but
g of the func
r function th
ction name f
PU) 1100
syntax of fu
ned functions
ctions.
as library fun
part of a pro
hich is not r
y are used.
e or function
Argument 2
n is sum, 2 p
with argume
tion
t is known as
ollowed by a
yllabus for 1
3
ction in C.
.
tions.
gram.
turning any
signature. It
, Argument
rameters ar
nt name.
function call.
list of actual
stmidsem ex
value from
consists of
) ;
passed to
.
argument
7/24/2019 C Language Basic Question
38/64
Da
Synta
An ex
2 Expl
Functi
whet
1. F
2. F
3. F
4.
F
5. F
1. F
rshan Ins
x or general
Funct i
at ement 1;
at ement 2;
at ement 3;
tion
st di o. h>
nt , i nt ) ;
( )
t a, b, ananf ( %d%d,
s = sum( a,
i nt f ( Answ
i nt x, i nt
t r esul t ;
sul t = x +
turn (resu
categories
lassified in on
returned or n
no argument
no argument
arguments a
arguments a
return multip
o argument
ction has no
es not return
re is no data
gineering
Function
i onName ( Ar
;&a, &b) ;
b ) ;
r = %d, a
y)
y;
t ) ;
f functions.
e of the follo
ot.
and no retu
and return
d no return
d one return
le values usin
nd no return
argument, it
a value, the
ransfer betw
& Technol
2
gument 1, A
ns);
wing categor
n value
value
alue
value
g pointer
value.
does not rec
calling functio
en the callin
ogy
r gument 2,
\ Functi on
\ Functi on
\ Functi on
based on w
\ void printli
\ int printlin
\ void printli
\ int printlin
\ void printli
ive any data
n does not re
function an
r gument 3)
Decl arat i
Cal l i ng
Def i ni t i o
ether argum
e(void)
(void)
e(int a)
(int a)
e(int a)
from calling f
ceive any dat
called functi
yllabus for 1
n or Si gna
ents are pres
nction.
a from the ca
on.
stmidsem ex
t ur e
ent or not,
lled
7/24/2019 C Language Basic Question
39/64
Da
Exam
2. F
Exam
3. F
E
rshan Ins
l e:
#i ncl ude
voi d pr i
voi d mai{
c
pr
pr
}
voi d pr i
{
i n
f o
{
}
}
nction with
When a fu
When a fu
l e:
#i ncl ude
i nt get _
voi d mai{
i n
m
pr
}
i nt get _
{
i n
pr
sc r e
}
nction with
When a fu
When it do
function.
ampl e:
itute of En
st di o. h>
t l i ne(voi d
( )
r s c r ( ) ;
i nt l i ne( ) ;
i nt f ( " \ n G
t l i ne(voi d
t i ;
r ( i =0; i
umber ( voi d
( )
t m;
get _number
i nt f ( "%d",
umber ( voi d
t number ;
i nt f ( "ente
anf ( "%d", &t urn numbe
rguments an
ction has ar
es not return
gineering
; / /
U \ n") ;
i ++)
( " - " ) ;
and return a
argument, it
urn value, th
;
) ;
) ;
)
number: " )
umber ) ;;
no return v
ument, it rec
a value, the
& Technol
3
No ar gument
value
does not rec
calling funct
/ / No a
;
/ / Ret u
lues
eives data fr
calling functio
voi
{Fu}
void mai{a = Fun1}
ogy
No ret u
ive data from
ion receives
r gument
r n val ue
m calling fun
n does not re
d main()
1()
n()
()
r n val ue
calling functi
ne data from
ction.
ceive any dat
NoInput
NoOutput
NoInput
Functionresult
yllabus for 1
on.
the called fu
a from the ca
void Fun{
}
int Fun1(){
return no;}
stmidsem ex
ction.
lled
()
7/24/2019 C Language Basic Question
40/64
Da
4. F
Exam
rshan Ins
#i ncl ude
#i ncl ude
voi d sum
voi d mai{
i n
pr
sc
su
}
voi d sum(
{
i f
el
} / /
nction with
When a fu
When a fu
ple:
#i ncl ude
#i ncl udei nt sum( i
voi d mai
{
i n
cl
pr
sc
x
pr
ge}
i nt sum( i
{
i n
w
{
itute of En
st di o. h>
coni o. h>
i nt , i nt ) ;
( )
t no1, no2;
i nt f ( "ente
anf ( "%d%d",
m( no1, no2) ;
i nt no1, i n
( no1>no2)
pri ntse
pri nt
No return
rguments an
ction has ar
ction has ret
st di o. h>
coni o. h>nt ) ;
( )
t no, x;
r s c r ( ) ;
i nt f ( "ente
anf ( "%d", &
sum( no) ;
i nt f ( "sum=
tch ( ) ;
nt no)
t add=0, i ;
i l e( no>0)
i =no%1
gineering
/ /
no1, no2: "
&no1, &no2)
no2)
( "\ n no1 i
( "\ n no2 i
val ue
one return
ument, it rec
urn value, th
/ / Ar gume
no: " ) ;
o ) ;
d" , x) ;
0;
& Technol
4
Argument
) ;
;
gretest")
gretest")
alue
eives data fr
calling funct
t
void{Fun
}
void main({
b = Fun1(}
ogy
;
;
m calling fun
ion receives
main()
(a)
)
Valar
F
ction.
ny data from
Value ofargument
No returvalue
i{
r
}
ue ofument
nctionresult
yllabus for 1
the called fu
void Fu{}
t fun2(f)
turn(e)
stmidsem ex
ction.
1(int a)
7/24/2019 C Language Basic Question
41/64
Da
5. F
Exam
#i
v
v
{
}
v
{
}
3 Expl
A
A
Exam
rshan Ins
}
r e}
nction that r
Function c
To receive
So functio
l e:
i ncl udey)
return
gineering
d+i ;
10;
iple value
er one value
e value from
lled with refe
x, i nt y ,
s, &d) ;
" , s , d) ;
a, i nt b,
formal argu
ction during
efinition of a
/ / Functi
ans;
;
d", ans) ;
) / /
x;
& Technol
5
/ / Ret u
r zero value.
function, we
rence not wit
i nt * s , i nt
i nt *sum, i
ment with e
function calli
function are
on Decl ara
/ / a an
x and y ar
ogy
r n val ue
It cannot ret
have to use
h value
*d);
nt *di f f )
xample.
g are called
alled formal
i on.
d b are act
f ormal ar
urn more tha
ointer.
ctual argum
rguments or
ual ar gume
guments.
yllabus for 1
n one value
nts or param
parameters.
nts .
stmidsem ex
eters.
7/24/2019 C Language Basic Question
42/64
Da
4 Expl
The p
C
C
Call
I
S
E
p
Exam
#i ncl
voi d
voi d
{
}
voi d
{
}
Outp
Enter
Value
X=5
rshan Ins
e
}
in call by v
arameters ca
all by value
all by referen
y value
call by valu
o the original
ven if a func
arameter, no
l e:
ude
7/24/2019 C Language Basic Question
43/64
Da
Value
X=3
Call
I
f
S
C
Exam
Outp
Enter
Value
X=5
Value
X=5
Differ
4 What
rshan Ins
s inside the
=5
y Referenc
call by ref
nction.
o the original
all by referen
ple:
#i ncl ude
voi d swa
voi d mai
{
i n
pr
sc
s
pr
pr
}
voi d swa
{
i n
t e
*x
*y
pr
pr
}
t:
the value of
inside the s
=3
inside the m
=3
ence between
do you me
itute of En
ain function
rence, the a
content of th
ce is used wh
st di o. h>
( i nt *, i n
( )
t x, y;
i nt f ( "Ente
anf ( "%d%d",
ap(&x, &y) ;
i nt f ( \ n V
i nt f ( " \ n x
( i nt *x, i
t t emp;
mp=*x;
=*y;
=t emp;
i nt f ( \ n V
i nt f ( " \ n x
& Y: 3 5
ap function
in function
two program
n by recursi
gineering
ddress of th
e calling func
enever we w
*) ;
t he val ue
&x, &y) ;
l ue i nsi de
%d y=%d",
nt *y)
l ue i nsi de
%d y=%d",
is marked a
ve function
& Technol
7
actual par
ion can be c
nt to change
of X & Y:
t he mai n
x, y) ;
t he swap f
x, y) ;
bold in call
Explain wi
ogy
meters is p
anged.
the value of l
unct i on) ;
unct i on) ;
y reference
h example.
ssed as an
ocal variable
rogram
yllabus for 1
argument to
through fun
stmidsem ex
the called
tion.
7/24/2019 C Language Basic Question
44/64
Da
Pictor
rshan Ins
Recursive
If a functi
Recursion
Suppose
write it as
computed
1!.which i
Ex: 4! =4
=
=
=
Terminatin
to infinite
ial presentati
f=1;if(..)..;f=4*fareturn
fact 4
itute of En
function is a
on calls itself
is thus the p
e want to ca
n! = n * (
as (n-1)!
s 1.
*3!
*3*2!
*3*2*1!
*3*2*1
g condition m
umber of pr
n of recursio
t(3)
4;
gineering
function that
then it is kno
ocess of defi
lculate the fa
n- 1) ! . First
( n- 1) * (
ust be there
cess.
n.
Tracing
f=1;if(..)
..;f=3*facreturn 6
fact(3)
& Technol
8
calls itself.
wn as recursi
ing somethi
torial of a gi
e have to fin
-2 ) ! . This p
which can ter
of function f
t(2)
;
ogy
on.
g in terms of
en number t
d (n-1)! an
rocess end w
minates the
ct() for n=4
f=1;if(..)..;f=2*facreturn 2
fact(2)
itself.
en in terms
then multipl
en finally we
hain of proce
(1)
;
yllabus for 1
f recursion w
y it by n. the
need to calc
ss, otherwise
f=1;if(..)..return 1;
fact 1
stmidsem ex
e can
(n-1)! is
late
it will lead
7/24/2019 C Language Basic Question
45/64
Da
Exam
Adva
Disad
5 What
Scop
rshan Ins
ple: Find fact
#i ncl ude
#i ncl ude
i nt f actvoi d mai
{
i n
pr
sc
f
pr
}
i nt f act
{i n
i f
{
}
el
{
}}
tages
Easy soluti
Complex p
vantages
Recursive
Terminatin
Execution
is scope, lif
The scope
accessible
In what pa
Local vari
of function
itute of En
rial of a give
st di o. h>
coni o. h>
i nt ) ;( )
t f , n;
i nt f ( "ente
anf ( "%d", &
fact (n ) ;
i nt f ( " \ n f
i nt n)
t f =1;
( n==1)
return
se
f =n*f a
return
on for recursi
rograms can
ode is difficu
g condition is
speed decrea
etime and vi
of variable c
rt of the prog
bles which a
.
gineering
n number usi
number: " )
) ;
ctori al =%
1;
ct ( n- 1) ;
f ;
vely defined
e easily writ
lt to understa
must; other
es because o
sibility of v
an be define
ram the vari
e declared in
& Technol
9
ng recursion.
;
" , f ) ;
olution.
en with less
nd and debu
ise it will go
f function call
riable?
as that a p
ble is accessi
side the bod
ogy
ode.
.
in an infinite
l and return a
art of a pro
ble is depend
of function
loop.
ctivity many
ram where t
s on where th
cannot be ac
yllabus for 1
imes.
e particular
e variable is
essed outsid
stmidsem ex
variable is
eclared.
e the body
7/24/2019 C Language Basic Question
46/64
Da
Lifeti
Visibil
rshan Ins
Global var
function in
e
Lifetime is
It is also r
ity
Visibility is
If variable
variable w
itute of En
iables which
a program.
a time limit d
ferred to the
the ability of
is redeclared
ich is redecl
gineering
are declared
uring the pro
longevity of
the program
within its sc
red.
& Technol
10
outside any
gram executi
ariable.
to access a v
pe of variabl
ogy
function de
n until which
ariable from
e, the variab
inition can b
a variable ex
he memory.
le losses the
yllabus for 1
e accessible
ist in a mem
visibility in th
stmidsem ex
by all the
ry.
e scope of
7/24/2019 C Language Basic Question
47/64
Dar
What
Decla
Initia
shan Insti
Co
is pointer?
A pointer i
Pointer is
Pointers c
manipulat
void main(
{
int
p
pri
}
Output: 10 p is int
& is ad
* is in
& oper
Va
ration of p
Syntax:
Example:
1)
The as
2) pt_na
3)
pt_na
lization of t
int a=5, x,
p = &a
x = *p;
tute of En
mputer P
How to dec
a variable t
derived dat
ntain mem
data stored
)
a=10, *p;
&a;
ntf(%d %d
10 5000eger pointer
dress of or r
irection or d
ator is the in
riable
a
p
inter,
data_ty
int *p,
erisk (*) tell
e needs a m
e points to
he pointer,
*p; // Decl
// Initia
// p con
ineering
ogrammi
lare and ini
hat contains
type in C.
ry address
in memory.
\\ A
d, a, *p,
variable
ferencing o
ereferencing
verse of * op
Valu
pe *pt_nam
loat *q, cha
s that the va
emory locati
variable of
res pointer
lizes p with
tains addres
5000
10
Technol
1
ng and U
Pointer
tialize it?
address or l
as their v
sign memor
);
erator whic
operator wh
erator ( x =
e
;
*c;
riable pt_na
on to store
type data_ty
ariable p an
ddress of a
s of a and *
gy
ilization (
cation of an
lues, so th
y address of
returns me
ich returns v
a is same as
e is a point
ddress of an
pe
regular var
gives value
CPU) 1
other variabl
y can also
a to pointer
ory addres
alue stored a
x = *(&a))
Addre
5000
5048
er variable
other variabl
iable a and x
stored at th
2nd Mid
0003
e.
be used to
variable p
of variable
t that memo
ss
e
t address.
em Syllab
access an
ry address
7/24/2019 C Language Basic Question
48/64
Dar
How
Arr
It r
Me
All
res
It i
Disc
Expla
As we
eleme
type k
shan Insti
ointer is di
ay is a const
efers directl
mory allocati
cates the m
ize or reassi
s a group of
ss relatio
int a[10],
Array nam
an array.
a[0] is sam
So every p
in Array of
have an a
nts of an arr
nown by sin
tute of En
fferent fro
Array
ant pointer.
to the elem
on is in sequ
emory space
ned.
elements.
ship betw
p;
is constant
e as *(a+0)
rogram writt
Pointers
ray of char,
ay will store
le name.
a:
ineering
array?
ents.
ence.
which canno
een array
pointer so a
, a[2] is sam
en using arr
int, float e
the address
a[0]
.
.
.
a[i]
a[1]
.
.
.
.
a[9]
Technol
2
Poin
It r
Me
t Allo
It is
and point
is constant
e as *(a+2),
y can alway
tc, same
values. So,
gy
ter variable
fers address
ory allocati
ated memo
not a group
r.
ointer and it
a[i] is same
be written
ay we can
rray of poin
a:
a+1:
a+i:
a+9:
Pointer
can be chang
of the varia
n is random.
y size can b
of elements.
always poin
as *(a+i)
sing pointer
have an arr
ters is a coll
*(a+0)
.
.
.
*(a+i)
*(a+1)
.
.
.
.
*(a+9)
2nd Mid
ed.
le.
.
resized.
It is single
ts to the firs
.
ay of pointe
ction of poi
2000
2002
2000+i*
2018
em Syllab
ariable.
element of
rs, individua
ters of sam
2
7/24/2019 C Language Basic Question
49/64
Dar
Synta
Exam
Now,
for(i=
{
}
By usi
dynam
SwapSwap
#inclu
void s
void
{
}
void s
{
}
shan Insti
:
data_type
le :int *ptr[5];
int mat[5]
he array of
;i
7/24/2019 C Language Basic Question
50/64
Dar
Write
#inclu
#inclu
void{
}
shan Insti
a C progra
de
de
ain()
int *p, a[1
p=a;
printf("Ent
for(i=0; i