CCP Set 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Inlroducion To C

dleueloped in the
lang C was
npro9mmmunq-

atb Boll, la
ab boll, touos
boratou'o
labona
Ridchie
eauly 19 10's
Cay by dennis

Chaattuistia of C Langag
uch Set built-in ntion
C .s a obust Jan9
and opetalor and
th
Combines featwes assembly languag9e
high deuel Aang
suutt od for
shuctveno. programming
C i s well
Code can be oganized as a coiloclron
One or mae funcuons.
s a portable language
proqramnng.
Pau'mauly useo fer y om
se
Compilo, librantes iturpratin ae phin
npleretlod n c

Stuctwua a e proeram'

d i r e c t i ues
ppuepoe D C e s s o r
GLobal de c l a r a l i o n s

main t)

Jocal declaration
s

Statesents,

Funchon1 ( )

Local dclar ali'ons

talermo4uty

Loyng deb
The peue proOssor diueciues cont ains ape caal
rbui cliono Ma indicate how o popaxe u
progsuam for compilalion
inoluodo <sAdio. h>
nt main)
The Oorld Qf
pxiul Cn twoltome. To
elnn O,

mainC)-&t
mainC) atiug point eor program eketubon

Files usecd in a C ouogami


T
owr Hoado objecb Exeeutable
file File

Souce ile - i exinsion deew codale . c


h extension
Headle jile
sh sbing.h er 8ung handing unc.
Stdlb h for Someu'scelanteiu fure.
&hdio. h tor shanolordizesl i/p fun ctoa
math.h - er machemabcal functuons
aloc h -hor dyNamie memoiy allocaha
comub.h eleanng screen and
bor conudle enput/eut
0bieet flo Analno b tha compile as a Nesut
s o r o codeHle unker le
le
PTOCRSS
o Upodua.
proRSSing an ekt tutabe uses ee
this )objece
bH combirung the objecb {2lut
tagetie
eruron er 6
( Binar elec exnoutabta hils- this cont aius bin as
Code oluclu is
allrustly executid Edeut/an in ndoo ere
USing comments compil ignoeg ( 9t
O1/ is useo to comnent a 1ngle
dint commont
Callod as

| ended tocth /-multtpte tine


Comme
Calleod as block Comment 8
USed or betlu vderskanoling dhe prngram.
usoid
Keyuoolcle C has a set oHesevuued
be uzed
olton Knouon ai KoycooAds that cannot
a an ddenifier 7tuy haue ekecl meanung
auto boeak Case cha Conat Continus

double enun extin er


nt Long. ugistivo utuwn3host
/8gmedl
unien urign Usto
slauet Loitch
| Iypedab
do shattc whil 3i2eb9obo
valatilo dolalult
a
helps to 4denu othe 'obreut i n
Idortifeu
basicab
w nanne cboognamgruen
Proga T4 i
vaslabl, auny and functions
o l m r such as dgit or un ndosole
a albkiabet ,
Thy may ceng s g
oTmeng ddonih Namis
Ruls T characteis or punctut
includa any gheceal
I t Cannot he undorscose
manles Ceg.##, , A, 9, e t
excapf - .

unelUsos.
be Two uccessi ue
Thoe Cannot6
cannot be useol a olenuo
dlentu
Keyooels the
ehara ctuu ab form
Cse
alphabet
The 1
sgnipeant, witu an alphabst
Jdlonth fes nan Nane musF bepin
The oleulioa
unde CONO møe that 3l characlee
3/ characiy
e an contain.

Juhoulol not
Name8
noElHLembu ml name
Vauicl J d e l f eu-
,

eyampls Weph. tode.


basic -pay,
HRA,
Tnvalu'd dolentrheu23 sduolouc
e m p - n u m b r

n a n . , #anpname , Co)
mae Kdaph-ro,
bas ie-Pa - HRA, aubo,
L e r 9 CLUbu
asic ata types in c
ta ype. eyoot 8 2e in Ran
us
ed
Byles
Characti char -

128 4o 12T To &rharaotos

Inttge int -32768 fo To 3tore inpr


32767 3Znmbey

Floating loat 3.4E-38to To 2do oe


ahrg
Pak'nt
3-4Et38 poi rtunbo
Doubla doubbe 8 TE- 308 to
Tos fo
17E+o8 pating
void pan unbel
Valucless Valuelo

The range c h a
is qiun as-128 to 127.
Note to stoo chaxaTB not numbea, 20
Chan gupposed eharacTa
at mmoy
Lshy this seange Reason is
aseutored u g tnetr AScIl codes. lor . charachd A
In memo- A usill be doiaol ag bine
has A Scil coda 65
6s
Jong. int -17483648 to 147Y9 3647
doublu 3 4E-4932 to I. tE+ Y
932
Vauabte manunumamas euuon to ths da
Storogo loeation un cemp u l a m o l
UMen cusng vaajab o, acualy
Oata tg/pes ae Used to
assgned to a vasiabe .
nott the type ovalu
Focir basie dala types in e au
nb,
ollowg-
a
cha float aud olouba
enua Ryutar
Oatatype v Van 2 Van
Aatatybes Classtfrcaluon
Basie atalypts aereuod lalalybeg U3e delinod
untt aso Datotypay
eha
Ploatt peint enwm
doubtaL
Basic a l a typer
OThe vaseuabo o pe int
Vasuablas o s eha hold a singla. Ascii ehamckos
enclos ed oiin tiv0 &inglo quoiis and
orcapy l byla
hace momof ounge 128 +o+ l27 -

For exa mple cha ch, aX


cha ch = 'e', as=

T hThe
e vasiableg o t p e float hold tho values awith
decimal onls and occepp fouu bytis memar spact
Range 3YE-38

loat X, age
loat p 3-1Y,
loat oge S,
hold
hold bytes
bytes % men
mem
double

T h e v a ables of type. oloCu


c e c n olo
mal
ca mal poent
þoent
value cesN
&pacetrat hold 7et308

7 6 209
Rdgc decebie. a
3.21Y5 26 ;
Exampe
C u 3u
e se
d d lo modnhy
lo modah
Modefre in knouon R
2ctakehrea
also
Modihos inc
ane
basic da ta. types
RIne d
uns1gnod

short

Gencaal Lyhax
KvataHe iit7;
basie datalype>
Kmodtihie 7
-
Exampe
= 3S
NOTE inE
oe Can
wnsigned noba aPpty ualehiko the float
b
i g e of deuba
-
we can i n ceeas
but
2uakife
usiTg Long ama ghsrt on
chaL

We Canmio oppY Leng

char /.c
Sgmed t h a
unsigned chon

3hedt int orint


he, Yd
unsigned ent

tonyint 1
tunsigred long i r t Lu

Apublo. 8
lorg l e s a
LA8 o 127
ehan byte
0 to 256
imed
cha
byt
9168 fo 32767
tnt
1474836Y8 to 2147,483,647

0 to G55 D5 r o to 4,29 4 96 7.21G


unsigne d
unt
b 768 to 2 16S7
shoxt mt byEes
O to 65 535
Shott i n byCs au7y83697
2147 y83 698 fo
Long byCis

4 bys o to Y.a P , 967, A15


wnsi9nod
Leng
. 6 - Y 932 to IE +9932
asuble
lo bys
19 decimal place.

-
Smbalie Constaut
kning symbeXte name.
A s s i g n m o n t oConsta
nts t o a

nama at
values aste asIgned to these
Conit amt
praýran.
he b eginning e t h
Syntax
#dopin 4ymbelie-name Value-ocenstant

Valid examplis i STRENTH 00


'
dohine
dehhu PASS-MARKS 50

tdehine MAX 00

#olepru. PI 14159
Callla
8e
8 erm
m ae
t it
m e sy
m 3
ase
mamee
ymbolic
tonstant ddenthiong eon t Pda
}do
blamb space belT
belT.eon
(a) no
Ruults-
Ruulls- Co)
(b) vse c a p l l o l t o l e

csLest
ehth&emi
Colon
LemicolN.
enos
n e i
C) be olnangd
)Valuu maynot
hertton i n t h rogrom.
progrom

complo duueeliu
duecliu
compilo
apeprocessor

olofine. As
Znvalud olopine X = .5
Idine N 25
define MAX t0

#Defne aRRAY 11
Edotine PRICE fvo
e clarin Censhamg

Censf nt classs 2= 4o;

Oe clau'g Vatab a Velatle

Volalil unb date


TO
these
cueimodoftcdlion
tionCse to tell expueutly the
Vallue
Compile hata vauable s
Votalile con
may change at any tume by
0
b
n t localt
ome exTanal. geuv ce ( rom
oule dle h e Program)
C a n be moduiacl, by is eon
progoa m

leng olake
ata Types Thec classea dala tpe
(a) Poumasy (er kondamontal) dataipes
(b) Oexiued data typas
(C) Use- doknod
data type
Inttge lypes
numberu tl a ang v a l u z
Inttgexs ase cohole
Suppostecd by a pasutcuela machir
Can e 3fored. dopenod
Size eo
The Size
The an intrger thal
n h e compulo
t a 2zo of the
cooMd Longths
I£ toe ue a l6 biE the suange - 32769
-82768 to
to
b sange
ittoo valtueis limitao

+2767- 15 bik tor


> A signod inllger
uges or bat er atgn and 15
and bi hor
tre . umber
t e hagnitamcde o
caN Bfore a n inlage Tanging
A 3 bit uosrdd ongEi
48 fo ,/y7,Y83, 6q7
om ,147,98 B, 6
oinliger
C uppoß 3 cla ssea
h o r t int 1
in bot sgned and unsigned
L o n g int joams.

for thi magrilkide


all the bié
unsigned intiges use

and ane aluoays posclive.


o ihi uunbe
6 b t machune the range e
Thorolere
Therefooe a a
be from Oto 6SS3S
unsigned inllge Numbel wel
Floating Point Types :-
number 3fored dn 3-2
(or teal) a9a
Flaatiny peënt mochnes) wib 6 digil, q\
and 32 bit
Con ale16 bit
peces ion
Keycoord loat
number d3 nat
tuonen
loat
accuracy- poouidod by
a

thepe double can h ugod to dafine


be
&uhtctort,
the numbe.

AA double data.type number wses 6 bli guing a

oligels hy aro kuouon a douba


pecisiorn 1
pe ciston numbers,
tHA pHLCLsLoN wlho, 0 may use long
To extend
double wwhich uses 8o bilg

void Types values


has no
The void. type
useol lo 8heci he
ype e unctens
Usa
Us uall The yp
iernThe ype a function is said to be
Void ohen it doe Nab seoliun amy value o
th caling funtion
Charaler Typ8
A 2/ngle. character can be olefineol, as a cbharact
char) ye data
lly stored in 8 6ils Cone byTe) o inlesnal
Vsua
torage
Vneigred char haee valus betivecn O and 3 s
Agned cha haue Vallls om-/28 Ao 7 ,
eclaration. af Vasuuables -
declasation does ivo htngs
thu vavuable nome
i) Ih tëlls the compila cohat tho vaxablo
data
i) IA specig as ushat po
Cusill hold
e c l a x a t i o n mut be dene. belore u/ng thu vauah.

Symhax oleclaring a vawuable


datatype VI, vR, Vni
vauablea.
V, V Vn are ama of
int coUTt;
Ekample i
int numbeer toal
doeble Salio

Vse-Alehined T9pe declaralion

a fealure knouon as ype-dafinition " trat


C support that uouid
to dehn an identejel
allus uses
an eype.
xis ttng data
pLkent
idestefeL Can latt be tus

The ser dehuned data ype


Thu
-

to declane viobles

GeneaL form typede, tupe identeter

exist'ng olatatype
iten fo t
ola toctyhs
tapedel int nils
bample tufpdey float make
wnits symboles int)
wnils batehl, baletu,
manc& namil5o, name 2C50],
The main. aduantage eg be
ype edey
dsh iis that we
coecat leaning ul, data tiypu narm fer dnowau
meaning[ul
e eeadiblluy othe prorem
Use-dened dataype enum
Enumealeo data trphe. i oleenool. a
enum
ddenlijier valie 1, value 2, .valuenf.
The
The identikex. is a
usee- dehned onumenalod data
cohuch Can b
ype usec o
Valuog
ole clare vtiablg Chat
can haue ome o e encloseol. lhin
braces CRuooU as enemeralion Constanß)

enun denlefHel V, VA -Vn;


The eneemeraled v t a b l e Vl, V2, ..vn can muy
hau one. of the Valrul, valuQ , . alien,
vals

xamp e enum day


Mondoy, TUAsdoy, Sunday
enum dla
ook-st, woek -eid
o0et-Bk = Monoloy
coeek-enol = Huday

TUsda
cocek-evud = 9aturodayy
TheCompiloL alomaliealuy ass1ons
6el beginning w t o a l l ntegen digi
Bu enuneralion
Censtanu
Assig
Assigning values to Vauialbles t
ValuOS can be assrgned. to vou abta eusIM
t

assignmert operaldr a follou


Vauable. - n a e = conatant
line
nnuultipl. assonment in ena
Cpes/nels hand
valuue on U uigh
CComuesct the gpe
side to the tyhe on th left
vale to valses t-
valses
tnetal
9ruing
'oocess o ealteol
uneliouzatior
dnelióluzatior

vasuables Cclle
unettal-valua = ° j
Eramppl
Hea yo +
nal valeu =
Int

MAX
y EZ
=
x

INPUT/ OOTPUT STATEMENT IN C

luso joTnmatling kunctioons


C Jaguage 2ppos
(a pint Cb) &can

pxinty Useoed to comuet daa stored in the program


jnto
t o aa to
2 t &boam f o oulput to the menilo

use0 to t e toet Aeam


Con cuet cemmue
Sranl i
dha keyboard to datau Values anol 8foras hen
pem
program VasLables.

These hunlieNN ae collecteealy knousn a anoao


Tnput/Oatut libravy
Header fle ineludo. (adolto, h>
pxinty)
&tands o r puint-omattin9
t h Use
OgLieed by
Used to olisplay- injorm.oilion. the vaxiables
values
and als0 pint. the
takes dala valuta, conuot
p i r funclions
The prirt.
The
them tb a tret oeea using. onatling funcdion
i a corbo6 pass " H encutting
Kound and pass
she cile ed.
R t Aeam to tu &tandrd output
Syntox: printg C"conbeol steirg
vauable Jiit).
he conBal siung may also
cenlain tho tict to
be prinlaal such
& insruclions to t u use, Caphón

sdertepe
CenholL chassaste like n lb, \m |a eto
can also e
icludeel

Exampu
to the LoOrld. oe languag")
print, C oelcCome
"

(a)
puinth Cn Rerat 7AJe /f", 13, 'a', 8);
(b)
Result: llal.8
ce) puicth Cn Reucutt : 7.d Je 7f, 12,' a, A:8);
Res ult: 2 o . 8
pavinatC"C"hl2Reuutt:2.83d\t %e\E 7f°, ,'a 3);
Result a

Ce) prent "la Result : 7d]t %c|E% 62f, 2,


2 , as 3718y

Rescult a 2YS37
pn C"n Yosetet: 5d |t x \E ZtHz", 231, 221,2 34);
Rescelt 234 EA OxEA

pht C'n 7he umber ù , 6d", 12) ;


The nuumbeu is

(A) peinH ("n The number i2d'", 1034);


The number is 2 Y
is 6 l , 1234);
(pint "n The numbo
Tha nuumbu JL8
numbe i - 6 d , 1234);
pruñt7 "/n The
The number
s 2B4
number s 0 6 d " ,
1234);
CK)pint C"nh
The number O0123
this itom is 09.0f
bintj ( "|n Tha puiee.
", 123. YS"6),
Lpees
0 0 / 9 4 S HupaLs,
this Jtem ik
The ppu'ce
beauilihulL");
This is \'9
(n) peintz C"|n
ThisiA0 beaulujul
77.4f \n 7. 2f Inf-7.af \n f n /lo Re
(n punth ("ln
In 11.ye. In 7-lo. 2en e", 98.76SY, 98-76SY,
98.76s4.
98 76SY, 98.76SY, 98.76SY, 98.T6sY,
99.76y):
() cha ch ='A';
Puint,("|n %c [n Z Dc \n /5c ", ch,ch. ch);
A
A
A
(P char st.C] "GHoad Moxni'ng
pint | a s*, st.)
Geod. Moan'ng.
pint Cn fdos, sb);
UaoloD IMoIR/NII IN1G7
Peint C"n. 2o:lo s ", st);
TT IIIGfo/olbj MRIN
PreuntCln 7s ", Att );
Gopd M1o

pintt Cn Y-2o los ", st);


Goed Mo ini

pi' Cn 7s', 3tu);


God Mornina
canf )
ands her scan fomatting and u3 ed. w uoad
Koyhoad.
foamattrod data from the
7he y n t a x :-

g , ag,g3, 9
Scanf (" conitiol &bung
3pecifog thO e a n d
forrnat
ceibel g6ting
has fo be obtained hm tt
ThThe
e
t hthe data that localion
tn monn
keyboardd and Bfored in
agumon
tg
the
poend by blank
blank spac
paca,
any
fundion igno Uzen
The The gca
Scan
newlns
enloned by
Jabs and
localLONS use nasd
we nood
values memo
- To store
addnes*
of thu variable is donoted by an
Th addiee
oeloood by thu name o t h vuabo
g
Examply Oimt num
QcanfC 7. d', knum);
l o a t salay;
Scanf C' ", salary);
(3) char ohj
Scant C" %e", Ach);
( 8 chal cbollo7;
Aean %s", s0)
- Scan Temunoliy aS 8ovN as i t eucouty
enanaclo
utnule
spae s
havacle Set - The charactinsin c axe gt0uped nto
ollorg Catogasues
(a) kettus Cc) &pecial chaua clixs
cb) Ogct (a) Lohiti sþaces
Aettos Uppocase. A . Z
Lowolcase, a z
ugcts edee decemal dipit 0... 9
SpeaalChaxaclis, Cpiod); :? T|Cbackslazh)
-Cunduscore) ? 7 2 Campexsa nda)
caet) * (asliisk -

(munus)+< Copnig
angle baackut er lesa thar)> Cclosing
angle braakot er
greal tan)
Clelt parenthosi Let brace
) igbt parentheis ught braa
numbu &'gn
Lohibt sbace blank space, horu zontal tob neuo ine .

uin e dthe &mallost indiudual


C-TOKENS pmegram
uni are kuouOn as C tokeng.

C tokens

Kay oods| Tdermikere||Corstonts|86uinga||Seual


Smbols toatog
oato

Constan Conshan in e deah to hiked valuu t a t


do not change duuing th exdcelTien e tho program
Constant
Numvuic ConLtart Chara. Consfans

Intgo Raal SIngte Sung


Corstanti Cemsfants Charact
Consha nti Consnt
Thero o
Conatanta sofva to seguona of digils.
Jnteg clecimal, octal and hia docima
types intiges
Oecimal intigers
consü a set o degili O thovugh.
Example 123 -321 65492/ +78
commms and non-di9it
chanactia anw not allod.
Shaces,
Octal cintage constauit conaüG o an combinatuono
set o thgh 7 uok wit a loading
odtiotes rorr cthe
ExamypLes 07 O495 0551
A pe ceedod by OX s
Saq cuonce af digis Ox er

Consiolesed as he xade imal untege,. May also includ


a0bha bet A through f r a tH%ough
Example Ox 2 Ox9E OXbcd Ox
2tored i mle daperdrt
T h e Lasegest wntige value dhat Can be
IA i 82767 in 6 bet ma chinas and 2,147,y83,647 em
-

3 2 - b i machihes

It à possibluL to store dasuge nligv donstan n


such as U,L and UL
thuse machine by appendin quali#ols
example 5678U or 56789u Cunsigmed. intie
987612347UL er ul
unsigned long int
876 54 3L r Leng. inage
maun C)
pouint C" Intäger vatus In|n ")
poeinty C" d d \n', 32767, 3 A7674+1,
print C"ln"); 3276 7 +10
print C"long intger. Valuuusn ln")
pinC" /Ld Zld Ld, 927674, 82167L+ll,
37672+ |oL);
Owtpal: Iuloge Valies
3276'7 -b768 -B7sy
Valliig8
Kong lnti qa
367 768 0777
Constanti
r sepeJesting nuumbess containing do cimal. po'nt
ike 7-548
Erampea 0083 O 7S 3S.26 t2U7o
Can also be exphees% eo n orponantial lsuentifc)
notalton
IS 6S may be uweull as 2156Se2
For Example -

2
ma
means by to-
mullby
manassa e exponant
Genval ferm
notalien s eallad loaling point torm
This 8-1863 -h2E-1
e- Set5
E x - 0 .6SeY
7SO000Oo00 7SE8 7.SE9
-

g-686 -
-
0.
OOooO0 B68

Stmgl Charat tønstant ushin a pau


pa
encloseol

single chara TÜe


Coritains
ingle .
quoti mark.
m ark.
,

valui
valuLL Cuouon a s A s c I £
7hu hau intege
output 97)
pxintf C"%o" , 'a') output a)
pinTy C"%e', 97) ;
2 b i n g lenatants -

chanaU0 enloseol in olguble.


Contatnt ge9ueune

Cbharaels may be numbeN, spe aak


she ces
hasa ctoe and blant

EX HELO" 1987,LoEl DoN6


5+9
Backalah chavaitu Conxrantu
Used in outpeut fundu6ng
Knouon a excape 309un ca
Constant Meansng
a audiblealut bete)
back spac
orm eedcau'ag suliun)
neu one Poge beak&
Caru cqe eolun move ha
pPoCuror
o fiet posi Hon
Aori2ontal tab esn
ine
Ventieal tab
2ingla eyust
double 9ust
uestion mark6
19 backshsh
Null

Vaniabl
Nataupo CAupporks thkee elasses data p
aimay fandamental dal pe
Tntigel (imt, short iut, Long imt
Soi vool dala ype
unsigrad nt
Ose doh'neel unsinad eont int
data pA unwgneok Long n
Chala c t ehal
8gn eo char
wtkignoad cla
Plootling point loat
odouble
Vordl Lerng odeub

You might also like