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

C Language {Unit 2(Part 1)}[1]

The document outlines the structure and components of a C programming unit, including sections on documentation, global declarations, and subprograms. It discusses variable declaration rules, data types, operators, and type conversion. Additionally, it provides examples of code snippets and their outputs to illustrate programming concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C Language {Unit 2(Part 1)}[1]

The document outlines the structure and components of a C programming unit, including sections on documentation, global declarations, and subprograms. It discusses variable declaration rules, data types, operators, and type conversion. Additionally, it provides examples of code snippets and their outputs to illustrate programming concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Unit

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

4global declorahiun sehions


în tho sechon we (an onk
wnt vanablukuncti ono
tunchon ’lwasiüi
4. when we dedare. the vanaoles as
ohen we delare he tunchoM golal kuqwod ard
We can aceus the voriases and
funchon thoughout
progran (uithin the dock % and outide the
d loty

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 -

it othe staring addren af th prognam


n shavts tom mainl ) sechom ony.
ony proqram Can
main ()

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

memay Ss: deperd) on Compil


(6 bi) 32 bit)
3- ong int

unicmed

tales eve takes t e


mumsn numbus
memay he:
4 long Long tnt
niqned ong long int
Takes tne
Takes trek-ve
numbey

mamoy hde : Syes (64 biH)


Character datatyre

Siqned chan unnqnd eha


tre X-ve.
fxe , Lbyle (3 bit)
mumony
ttoat datatyg
druble long doue.
ftot

po 6 deumal
ponts

qkeyte (32bith)
Caleulak rarge Sqrcdb m’ bits.
-gtoa 1

to i

fornat Specifers- it tels the Compilea about he kre d


data.
Short int - /.d
uniqned shert int u
int - /.d
liqned iot - 2u
lon int - d
unsiq ned long in 7 lu
Long long int - ld

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 ()

pmt} (".d n",Pab);


3
$ge tiename.
*laout

..
with undentore
indude <stdio b:
void veain)

# include <tdip.h>.
void main( )
int @21;

ge ename.
/a-out

pen cane /lewnca


void main)
int Aa (0,
prt("7.d n", ba);

.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

pHnt ("d \n, a-b), V5


printy (".dn atb); /s0
prit+ ("y. dn', a/b))/2
prit4 ("dIn" a. b), lo
a Relational cpenaton or Comqarion ejerohors
Opraton Meaning
is tem than

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

pmt ("d " a<-b); JL

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

pntt (".dìn", c); /0


COpeator Mronirg

- 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

fist valuc d a wint. bys


Sint value dasang hehy
then will be inc.
thun valu d a will
code
#incude <stdio.hy
Void mun ()
Sutput
int valu :10;
primt4("dtr',vatua); /i0 1|
prnt ("d \rb ++ valut); /) 12
1)
1)
pmtf (Mydln"valua+); /

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

$gee flk rame.e

Note aRON6
direey
pe»s bo TRY oNt
Honewo.

Convating one data tyre into anotfer data tupe is knouon


as

type corveslon.
4 ovesjun
J

împlcit Erpliciv
(svesin lonversin.

vold man()

Chay t ' s ' 23


83-000000
83:
S

#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;

6) inlude<stdio.h> void maicol)


Void main).
nt a:10
Cont int a210
prtg (y.hn),a); (ho
int 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';

prt (" y. din')a);)| s2

. 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.

*(points). Repreents sthael


unions
G. ) (lomna) ) a [ , 56, .

(Sermi- colon) ’ît els tke Complen end


Prproeno.
8. # (hash) Replesats
9. = (omgmmnt)’ a:5, b 10,
Condi tionat staternents i
It is a staterment,that deDtribes the
the too Qventi based on certaD Condihons.
ib stakement

True
Conditon

False
Staternenti

End it k

6 the condi tion is true, coresponding staternent,


be exeeu tec,. oteruie ,it Yeaches the erd of boi
1. Check /wite a Cpgan to cug lay a nglu
#include <Stdiob>
void oin()
inta -
i7 (axo)

TO Overcome,no output in if shattrment ik it doent


Satisty the Condihen we use ELSE Statenert
’reprSat AopRE33 of the vavasle.
9.0nte a 3 numsey
uing
Cygrag,
Stateme.
tb fnd the argo»t of
#inlude < stdio.b
yoid noin ()
int a:5, b:10, c1S;

pontg(ais gratn tkan by e"),

You might also like