C Language {Unit 2(Part 1)}[1]
C Language {Unit 2(Part 1)}[1]
Furdamertals oCprgm
structure sechons
k entire structure can be clasifcd nto 6
1.documentotion sechon
Q reproceLor echo
3. definiion secion
4 qlobal declaration secfioo
6. Sub Prgram setion
1.0ocumentation sehon
In thu sectioo we Can wñte the descnphon of the
Code by tx help of toMIDethi
gram name: sum ot tuwo numbS
programmen name: shok
dat : 22-09 -2024
time. l0:s6arn
Comment - it telle the topiler akout ttx dux iphon byA
the help of symboie oay.
în claquag we can divide two types ¢ ommerto
Single line comments ;- |/
mulh tine tomment :- /* */
Note:
Compi ler simply ignoreo the CormYento in:
yrOID SeLho#)hash
fn thy Sechio, we can wnte hadu iles.
isregroceuon(pe- bofrc)
bege comçiling. the code procesr roun the enire
Code it incudes,
1. ineudes the
9. tontrolu the ins of ade,/
3.8. Speatfcalion h arrer mevsgs
fincude<stdoh>
stndad input y output -sarf(>
device - kayband
Standlad igut davice "moritor - n o
tondd
main()A output
tuncti
math.h>
# indudok
)
Noe'
funchon Can be
paol
yprexnted an a
Ces)
tan(
defnitigseativn wit Comutat vaiabs
sechon we Can
în h s the valen.
Cen stose
Variat: which
a210
be20
C40 the vao ble ay a cotant
Corstont: when we deelane
we connot charge the valutb throghout the progtars.
Cit i a afred ).
declanng the content vaalu
Cynta tordatay
#DEFINE a-10
Consa
braes
Q. ohen we declare the vaiate o the funchon ay tocal,
W2 anaceem the vaiay and funchns nthun t
Scope dthe blouk.
5.Main &ettog -
Ilscoge of if block
6 Sub proqrams sectisn
in thw sectipn, we can wnt tnL Wser
deired tunctiony.
Syntoz tur dectaring wer dejined turch ong /
(body the statenneno
Data Mpg
It s ntg but he tup o the Stored infongaion.
it specife tyfe af he ala, that Con'b stovê
yntax
ncg ftal, haas and ing, et
dabahype vanablt nam= yalue.;
when wer the compilar chuks the ituthan aubornahaly
idn hheny
rame of the vanal
And how much mmy T0quird for the vanae.
(lawiicahon f data yo
IpedchndtaBahgen:
inge
3. charate
4-void
2 duured data
1.funcho
3gointos
3 uac dutind databyru
1.Stuhws
J. unioy
3-bypedet
4enumratn
1 predeined datatyg!
intaer-it acLepto nohole nurmby (o to oo)
t daun't aupt gachioral poins
toat- it acopt tathoral printo.
choractus -t acupo, digrt, auphaseta speial smbols
(o-) (a-z)(0-a)', (et$)et. trij)
There are 222 speual charaets (it., AsCII)
Jrneitan stardard tode tor ingrmahon tntevcharge
clanitation
.hot nt
sing
J.
iqncd ungiqned
shant intd Shot iot
by du<cult it takeo
yNo Ned it take) ony tenueneny
uutiy runby
Ssize abyBes- 16 biff
a.int
(unsiped in
Chn
tckes
ne numbs
éaes
te ne
numhs
unicmed
po 6 deumal
ponts
qkeyte (32bith)
Caleulak rarge Sqrcdb m’ bits.
-gtoa 1
to i
UNicnd chan - , C
RANGL
tinsignd
Short int: | ehort int:
O to a 1
R. int Q, int
- 0 to 1
0 to -1
3.
long int long int
- to 6 to
(
ang long
to 1
6. Chan cla
-atto -1.
b. float 6. tloat
. dui
4. dousle
6
to &1
doulle
lorg
9
* Vañades 3 its ules *
vaia ble s a name, ven to the element tor stoving the
infprmaion. NOte
for declanrg the varase:
Syotazdatatype TheYe are 3
vanaslename; kywerd in c
Syntar tor inithializirg the vaiale
otatype vamastername avalue;
Rules for declaring the vasables
1.1here should not be given keyuword os a vanasle-nane.
9. The muit be ngapaces iD variable name.
3.Cannot start th the diqis.
can start wih the undercore symbol.
6. (anot start wilth the speial ssmbol (eg. ,*,e.t.t.y)
B- Can start with eithu ujpRrcaje' or lowerase tetters.
a wnte a C proqiam to deelar vanable ánd apply 6rules
*irrude <stdio.b>
void main ( ) Output
iot a:25;
priny(dn", a);
ReeIved or biitio words
$ "/a-out
ist of KEYORDS avoailasiu in ( bray
auto onst double toat iot shoyt strict unsqrd
break tonhnue eue
tor long signed suich vod
defautt enum goro eükr Saottypdef volaik
char do etrn rehun s tabe urio) whila
Q. sitt
# incude <stdio.b>
void main()
int a b : 10}
aut
with digits
tinlude stdibb>
Void main ()
..
with undentore
indude <stdio b:
void veain)
# include <tdip.h>.
void main( )
int @21;
ge ename.
/a-out
.Dut
Opevators
Oprator s a special <ynbol ,that an porfoirn oprrationt An
optiard
Oator act on some vanable names alled
A+B
A,B- opev ands
eprator
opration ’ Sum
opeTaor act on Single varable talled unary opeYator
NOtei;- An birony cpolu
Note 2 !-
An operator atla on two vanables o alud temay
operator act on thru va nasle io called
ope ratr.
qevator Meani
Addihon or uray plus
eubtrachon er unay minus
Mulkpication
Oivuion
Modulo divi
(rehuna, rnaindea )
Code e
#include <Stdioh>
Out ut
void main () 16
5
int ast0, b:5j 50
grcolon
is not qual .
’ True
Code -
output
#icude <tdiob>
void main() OHOHO 1
int a=0;
int b0)
pònt+ ("rd", a>b); Mo
pront+ ("n y.d \n", acb); |2
acut
3 ASsiqnment oyevaton as 10
Gpetos Meaning
C a+:5; (ie., a: at5)
C-15;
Straton asign C- -5;
Mutipicaio C= 50,;
Codes t20
#include< Stdio.h>
Void rain () utpu
int a= 10
10
I00
prott ("%d In," c); /o
pri4 ("/d n'", c)/z0
pnt (d \n' ); tb
C*-aj
- lonialoR
logica! Nof.
Code
# Irctudestdio-h> Qubput
void main()
int a:10,
jnt b: 20';
pnnt ("d lr, (acb) kk (a=b); /o
prott ("%din", (acb) 1M(a:b), /1
/a.out
A B A&8 Al|8.
T T T
T
T T.. T
ÎncrementDenenert opvato) -inc.Jdeu
- the value by.
Erparmioy
epnaBr
Pot inremesh
pre deremt
pot deenement.
5)
++j
9gce tflaname.
6. Conditonal oy îernary cpraor
Rsalant.
waue
VariaBe prenioni tnpronin2 :txproin)
falhe
Reultant
valu
Fint enpemiorl in evaluated, ikij itiw
ttio tu crpa ii
be eretuted (result oyored info anablb).i6 he expn;
fale, expa will b neukd(vut osored hinb
Vaniase)
numer
Q.oñte a proqiam to frd out the Man-
tenay, tondihgrgl operaor.
inck <stdio-h
void main U 10.
iot a: tD, b=5;
int To: (a5b) a;b)
$ gce ilerame.c
$. fa-out
(Metted a.
# inude <tdio-h>
void rain()
int az 10 ,bt5j
Note aRON6
direey
pe»s bo TRY oNt
Honewo.
type corveslon.
4 ovesjun
J
împlcit Erpliciv
(svesin lonversin.
vold man()
#inudastdlo.by Q30000o
void rnain( )
oat
Jlat 0000D
prit "1y tn', ); as.4
poöt (" \n' sum); lay. y0000D
pmkË ("% dtn', int(sum); lay docs8
cleuk
.
Constanly nd ih typ i
when we deelaYe the Conutant
vamalle as
onot change the values througbout tY
cannot prgram (i
ted).
Sytaz or dectansg the Corwtnt vanasle
Const clatatype vaneßlename value;
Wnte a cprogam, to mple ment the constant van
Q tinclude <stoio h
O+include<stdio-h vojd mainl)
void main ( )
Cot isot aei0
const int a:10; prDtt ("%.dina); Ir
a=20;
Conict erer
#include <tdio.b>
Veid mcs)
int a-20)
enef
ypeo Constant -
s.1nteger constanls : acepQ only uohok numtes Co to oo) : l45,6
elot Costants accepts facional points. g: 6.0,26.
. charact Constan;acopb oliih,alFhaselo &speial Gymách (o2-an
Notes- charactos can be encloyed coith
4- Shing Contant: t u a collec tien 4 chavacten'o Sequure f
chajatttrn that an be enclosecd oith (doule guoten).
0 wnte ac program to pont Charackr on Iha
jnoude <tdo.h>
void mcuin ()
Snt a R';
. wDte Sem
to rint sny vale SRM
the dinplay
#incudeadio.h
Void mub()
SRm urivernik
char at J "SRM universitg" 3
printf (".s\n', a);
Speclal Syrkaa
Square biakets.
. ( ) - paran hess Rpsesat.
True
Conditon
False
Staternenti
End it k