0% found this document useful (0 votes)
45 views

(PIC) C Programming-WPS Office

This document provides an introduction to the C programming language. It discusses that C uses variables to store values, programs are structured with functions for defining and calling code, and input/output can be directed to terminals or files. C allows precise control of input/output compared to languages like Fortran or Pascal. While powerful, C also allows producing unreadable code, so care must be taken when using it.

Uploaded by

Ashita Rawate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

(PIC) C Programming-WPS Office

This document provides an introduction to the C programming language. It discusses that C uses variables to store values, programs are structured with functions for defining and calling code, and input/output can be directed to terminals or files. C allows precise control of input/output compared to languages like Fortran or Pascal. While powerful, C also allows producing unreadable code, so care must be taken when using it.

Uploaded by

Ashita Rawate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CPr

ogr
ammi
ng
AnI
ntr
oduct
ion

 AboutC

Asapr ogrammi nglanguage,Cisratherli


kePascal orFor
tran.
.Val
uesarestoredin
variables.
Pr ogramsar estruct
uredbydef i
ningandcal l
i
ngfuncti
ons.Pr
ogram fl
owi scontr
oll
ed
usingl oops, i
fstatementsandf uncti
oncalls.I
nputandoutputcanbedirect
edt othetermi
nalor
tofiles.Relateddat acanbestoredtogetherinarray
sorstructur
es.
Ofthethreelanguages,
C
all
owst hemostpr ecisecontr
olofinputandout put
.

Cisalsorat
hermor et
ersethanFort
ranorPascal.Thiscanresul
ti nshorteffici
entprogr
ams,
wheretheprogr
ammerhasmadewi seuseofC' srangeofpower fuloperators.I
talsoall
owsthe
progr
ammert oproduceprogramswhichareimpossibletounderstand.Programmer swhoare
famil
iarwi
ththeuseofpointers(
orindi
rectaddressi
ng,tousethecor rectterm)will
welcome
theeaseofusecompar edwithsomeotherlanguages.

Undiscipl
ineduseofpoi nterscanleadtoerrorswhichar everyhardtotr
ace.Thiscourseonl
y
dealswi t
ht hesimplestappli
cationsofpointers.I
tishopedt hatnewcomerswillfi
ndCauseful
andfriendlylanguage.Caremustbet akeninusingC. Manyoft heext
rafaci
li
ti
eswhi chi
toff
ers
canleadt oext r
atypesofpr ogramminger r
or.Youwi llhav
etol ear
ntodealwit
ht heseto
successfull
ymaket hetransit
iontobeingaCpr ogrammer .

 CommonC

Unt i
lrecentl
ytherewasonedomi nantf
orm oftheCl anguage.Thiswasthenati
veUNI Xf
orm,
whi chforhi
stori
calreasonsisknownaseitherBellLabsC, af
terthemostpopularcompil
er,or
K.R.C, af
tert
heaut horsofthemostpopulartextbookont helanguage.I
tisnowoftencal
led
"ClassicC"

 ANSIC

TheAmer i
canNat i
onalStandar
dsI nst
it
utedefi
nedast andar
df orC,el
iminat
ingmuch
uncert
aint
yabouttheexactsynt
axoft helanguage.Thisnewcomer ,
call
edANSIC, proclai
ms
i
tsel
fthestandardver
sionofthelanguage.Assuchi twil
li
nevi
tablyover
take,andeventuall
y
repl
acecommonC.

Thiscour
seint
roducesANSICsi
nceiti
ssuppor
tedbytheSUNwor
kst
ati
oncompi
l
ers.MostC
pr
ogrammingtext
sarenowavail
abl
einANSIedi
ti
ons.

Thiscour
seint
roducesANSICsi
nceiti
ssuppor
tedbytheSUNwor
kst
ati
oncompi
l
ers.MostC
pr
ogrammingtext
sarenowavail
abl
einANSIedi
ti
ons.
ASi
mpl
epr
ogr
am ofC
Thef
oll
owi
ngpr
ogr
am i
swr
it
teni
ntheCpr
ogr
ammi
ngl
anguage.

#i
ncl
ude<st
dio.
h>

mai
n()

{pr
int
f("
Progr
ammi
ngi
nCi
seasy
.\n"
);
}

Anot
eaboutCPr
ogr
ammi
ng

I
nC,l
owercaseandupper
casechar
act
ersar
everyimpor
tant
!Al
lcommandsi
nCmustbe
l
ower
case.
TheCpr ogr
amsstar
ti
ngpoi
ntisi
dent
ifi
edbythewor
dmain(
).

Thisinf
ormsthecomput
erast
owher
ethepr
ogr
am act
ual
l
yst
art
s.Thebr
acket
sthatf
oll
ow
thekeywordmain

i
ndicatethatt
herearenoargumentssuppli
edtothi
sprogr
am (t
hiswi
llbeexami
nedl
ater
on).Thetwobraces,
{and},signi
fythebegi
nandendsegmentsoftheprogr
am.Thepurposeof
thestat
menti ncl
ude<stdi
o.h>istoall
owtheuseofthepri
ntf
.

statementt
oprov
idepr
ogr
am out
put
.Textt
obedi
spl
ayedbypr
int
f()mustbeencl
osedi
n
doublequot
es.

Thepr
ogr
am hasonl
yonest
atement:

pr
int
f("
Progr
ammi
ngi
nCi
seasy
.\n"
);

pri
ntf(
)isact
ual
lyafunct
ion(
procedur
e)inCt
hatisusedforpr
int
ingv
ari
abl
esandt
ext
.Wher
e
t
extappear
sindoubl
equotes""
,iti
spri
ntedwi
thoutmodi
fi
cati
on.

Therearesomeexcept i
onshowev er.
Thishastodowitht
he\and%character
s.These
char
acter
saremodi fi
er'
s,andforthepresentt
he\f
oll
owedbythenchar
acterrepr
esent
sa
newl
inecharact
er.Thustheprogram pri
nts

Pr
ogr
ammi
ngCi
sesi
aly:

Thecursori
ssettothebegi
nni
ngofthenextl
i
ne.Asweshal lseelat
eron,whatf
ollowsthe
\
charact
erwil
ldet
erminewhati
sprint
ed,
ie,at
ab,clearscr
een,cl
earli
neet
c.Anotherimpor
tant
t
hingt
orememberisthatal
lCstat
ementsaret
erminatedbyasemi -
colon;

Summar
yofmaj
orpoi
nts:
 pr
ogr
am execut
ionbegi
nsatmai
n()

 key
wor
dsar
ewr
it
teni
nlower
-case

 st
atement
sar
eter
minat
edwi
thasemi
-col
on

 t
extst
ri
ngsar
eencl
osedi
ndoubl
equot
es

 Ci
scasesensi
ti
ve,
usel
ower
-caseandt
rynott
ocapi
tal
i
sev
ari
abl
enames

 \nmeansposit
iont
hecursoront
hebegi
nni
ngoft
henextl
i
nepr
int
f()canbeusedt
o
di
spl
aytextt
othescreen.

 Thecur
lybr
aces{
}def
inet
hebegi
nni
ngandendofapr
ogr
am bl
ock.

#EXERCI
SEC1:

Whatwi
l
lthef
oll
owi
ngpr
ogr
am out
put
?

#i
ncl
ude<st
dio.
h>

mai
n()

{pr
int
f("
Progr
ammi
ngi
nCi
seasy
.\n"
);

pr
int
f("
Andsoi
sPascal
.\
n")
;}

 @ Pr
ogr
ammi
ngi
nCi
seasy
.Andsoi
sPascal
Andt
hispr
ogr
am?

#i
ncl
ude<st
dio.
h>

mai
n()

{pr
int
f("
Thebl
ackdogwasbi
g."
);

pr
int
f("
Thecowj
umpedov
ert
hemoon.
\n"
);
}

Thesy
mbol
soft
heast
hmat
icoper
ator
sar
e:
Oper
ati
onOper
ator
Comment
Val
ueofSum bef
oreVal
ueofsum af
ter

Mul
ti
ply
*sum.=sum *2;
48

Di
vi
de/
sum. =sum /2;
42

Addi
ti
on+sum.=sum +2;
46
Subt
ract
ion-
sum =sum -
2;42

I
ncr
ement
++++ =sum;
45

Decr
ement
--
-- =sum;
43

Modul
us%sum.=sum %3;
41

Thef
oll
owi
ngcodef
ragmentaddst
hev
ari
abl
es

 l
oop

 count

t
oget
her
,leav
ingt
her
esul
tint
hev
ari
abl
esum

Sum=l
oop+cout
:

CTokens

Ther
ear
eCTokens:

Al
phabet
s at
oz,
AtoZ

Numer
ic 0,
1to9

Speci
alsy
mbol
s (
),!,
?,@,
$,*,
+,/,
=

Theset
okensrepresent
sini
ndiv
idualent
it
yofl
anguage.
Thefol
l
owingdiff
erentt
ypesoftokensar
eusedinC:

I
dent
if
ier
s

Key
wor
ds
Const
ant
s
Oper
ator
s
Punct
uat
ionsy
mbol
s

Thanky
ou

You might also like