You are on page 1of 70

This Download is from www.downloadmela.com .

The main motto of this website is to provide free download links of ebooks,video tutorials,magazines,previous papers,interview related content. To download more visit the website. If you like our services please help us in 2 ways. 1.Donate money. lease go through the link to donate http!""www.downloadmela.com"donate.html 2.Tell about this website to your friends,relatives.
Thanks for downloading. Enjoy the reading.

#isit

http!""www.downloadmela.com"

for more papers

1. What will be the output of the following code? void main () { int i = 0 , a[3] ; a[i] = i++; printf (%d",a[i]) ; } Ans !"# o$tp$t for t"# a%ov# &od# 'o$(d %# a )ar%a)# va($#. *n t"# stat#m#nt a[i] = i++; t"# va($# of t"# varia%(# i 'o$(d )#t assi)n#d first to a[i] i.#. a[0] and t"#n t"# va($# of i 'o$(d )#t in&r#m#nt#d %+ 1. ,in&# a[i] i.#. a[1] "as not %##n initia(i-#d, a[i] 'i(( "av# a )ar%a)# va($#. ................................................................................................. /. Why doesn't the following code give the desired result? int 0 = 3000, + = /000 ; (on) int - = 0 1 + ; Ans 2#r# t"# m$(tip(i&ation is &arri#d o$t %#t'##n t'o ints 0 and +, and t"# r#s$(t t"at 'o$(d ov#rf(o' 'o$(d %# tr$n&at#d %#for# %#in) assi)n#d to t"# varia%(# - of t+p# (on) int. 2o'#v#r, to )#t t"# &orr#&t o$tp$t, '# s"o$(d $s# an #0p(i&it &ast to for&# (on) arit"m#ti& as s"o'n %#(o' (on) int - = ( (on) int ) 0 1 + ; 3ot# t"at ( (on) int )( 0 1 + ) 'o$(d not )iv# t"# d#sir#d #ff#&t. ................................................................................................. 3. Why doesn't the following statement work? &"ar str[ ] = "2#((o" ; str&at ( str, 454 ) ; Ans !"# strin) f$n&tion str&at( ) &on&at#nat#s strin)s and not a &"ara&t#r. !"# %asi& diff#r#n&# %#t'##n a strin) and a &"ara&t#r is t"at a strin) is a &o((#&tion of &"ara&t#rs, r#pr#s#nt#d %+ an arra+ of &"ara&t#rs '"#r#as a &"ara&t#r is a sin)(# &"ara&t#r. !o ma6# t"# a%ov# stat#m#nt 'or6 'rit#s t"# stat#m#nt as s"o'n %#(o' str&at ( str, "5" ) ; ................................................................................................. 7.

#isit

http!""www.downloadmela.com"

for more papers

How do know how many elements an array can hold? Ans !"# amo$nt of m#mor+ an arra+ &an &ons$m# d#p#nds on t"# data t+p# of an arra+. *n 89, #nvironm#nt, t"# amo$nt of m#mor+ an arra+ &an &ons$m# d#p#nds on t"# &$rr#nt m#mor+ mod#( (i.#. !in+, ,ma((, :ar)#, 2$)#, #t&.). *n )#n#ra( an arra+ &annot &ons$m# mor# t"an ;7 6%. <onsid#r fo((o'in)pro)ram, '"i&" s"o's t"# ma0im$m n$m%#r of #(#m#nts an arra+ of t+p# int, f(oat and &"ar &an "av# in &as# of ,ma(( m#mor+ mod#(. main( ) { int i[3/=;=] ; f(oat f[1;3>3] ; &"ar s[;??3?] ; } ................................................................................................. ?. How do write code that reads data at memory location specified by segment and offset? Ans @s# p##6%( ) f$n&tion. !"is f$n&tion r#t$rns %+t#(s) r#ad from sp#&ifi& s#)m#nt and offs#t (o&ations in m#mor+. !"# fo((o'in)pro)ram i(($strat#s $s# of t"is f$n&tion. *n t"is pro)ram from A8@ m#mor+ '# "av# r#ad &"ara&t#rs and its attri%$t#s of t"# first ro'. !"# information stor#d in fi(# is t"#n f$rt"#r r#ad and disp(a+#d $sin) p##6( ) f$n&tion. Bin&($d# Cstdio."D Bin&($d# Cdos."D main( ) { &"ar far 1s&r = 00E>000000 ; F*:G 1fp ; int offs#t ; &"ar &" ; if ( ( fp = fop#n ( "s&r.dat", "'%" ) ) == 3@:: ) { printf ( "Hn@na%(# to op#n fi(#" ) ; #0it( ) ; } II r#ads and 'rit#s to fi(# for ( offs#t = 0 ; offs#t C 1;0 ; offs#t++ ) #isit

http!""www.downloadmela.com"

for more papers

fprintf ( fp, "%&", p##6% ( s&r, offs#t ) ) ; f&(os# ( fp ) ; if ( ( fp = fop#n ( "s&r.dat", "r%" ) ) == 3@:: ) { printf ( "Hn@na%(# to op#n fi(#" ) ; #0it( ) ; } II r#ads and 'rit#s to fi(# for ( offs#t = 0 ; offs#t C 1;0 ; offs#t++ ) { fs&anf ( fp, "%&", J&" ) ; printf ( "%&", &" ) ; } f&(os# ( fp ) ; } ;. How do compare character data stored at two different memory locations? Ans ,om#tim#s in a pro)ram '# r#K$ir# to &ompar# m#mor+ ran)#s &ontainin) strin)s. *n s$&" a sit$ation '# &an $s# f$n&tions (i6# m#m&mp( ) or m#mi&mp( ). !"# %asi& diff#r#n&# %#t'##n t'o f$n&tions is t"at m#m&mp( ) do#s a &as#.s#nsitiv# &omparison '"#r#as m#mi&mp( ) i)nor#s &as# of &"ara&t#rs. Fo((o'in)pro)ram i(($strat#s t"# $s# of %ot" t"# f$n&tions. Bin&($d# Cm#m."D main( ) { &"ar 1arr1 = "Li&it" ; &"ar 1arr/ = "6i&it3a)p$r" ; int & ; & = m#m&mp ( arr1, arr/, si-#of ( arr1 ) ) ; if ( & == 0 ) printf ( "Hn,trin)s arr1 and arr/ &ompar#d $sin) m#m&mp ar# id#nti&a(" ) ; #isit

http!""www.downloadmela.com"

for more papers

#(s# printf ( "Hn,trin)s arr1 and arr/ &ompar#d $sin) m#m&mp ar# not id#nti&a(" ); & = m#mi&mp ( arr1, arr/, si-#of ( arr1 ) ) ; if ( & == 0 ) printf ( "Hn,trin)s arr1 and arr/ &ompar#d $sin) m#mi&mp ar# id#nti&a(" ) ; #(s# printf ( "Hn,trin)s arr1 and arr/ &ompar#d $sin) m#mi&mp ar# not id#nti&a(" ) ; } ................................................................................................. =. Fi0#d.si-# o%M#&ts ar# mor# appropriat# as &ompar#d to varia%(# si-# data o%M#&ts. @sin) varia%(#.si-# data o%M#&ts sav#s v#r+ (itt(# spa&#. Aaria%(# si-# data o%M#&ts $s$a((+ "av# som# ov#r"#ad. Nanip$(ation of fi0#d.si-# data o%M#&ts is $s$a((+ fast#r and #asi#r. @s# fi0#d si-# '"#n ma0im$m si-# is &(#ar(+ %o$nd#d and &(os# to av#ra)#. And $s# varia%(#.si-# data o%M#&ts '"#n a f#' of t"# data it#ms ar# %i))#r t"an t"# av#ra)# si-#. For #0amp(#, &"ar 1n$m[10] = { "9n#", "!'o", "!"r##", "Fo$r", "Fiv#", ",i0", ",#v#n", "Gi)"t", "3in#", "!#n" } ; *nst#ad of $sin) t"# a%ov#, $s# &"ar n$m[10][;] = { "9n#", "!'o", "!"r##", "Fo$r", "Fiv#", ",i0", ",#v#n", "Gi)"t", "3in#", "!#n" } ; !"# first form $s#s varia%(#.si-# data o%M#&ts. *t a((o&at#s 10 point#rs, '"i&" ar# pointin) to 10 strin) &onstants of varia%(# si-#. Ass$min) #a&" point#r is of 7 %+t#s, it r#K$ir#s O0 %+t#s. 9n t"# ot"#r "and, t"# s#&ond form $s#s fi0#d si-# data o%M#&ts. *t a((o&at#s 10 arra+s of ; &"ara&t#rs #a&". *t r#K$ir#s on(+ ;0 %+t#s of spa&#. ,o, t"# varia%(#.si-# in t"is &as# do#s not off#r an+ advanta)# ov#r fi0#d si-#. ................................................................................................. >. The !pawnl" # function... 89, is a sin)(# tas6in) op#ratin) s+st#m, t"$s on(+ on# pro)ram r$ns at a tim#. !"# ,pa'n(( ) f$n&tion provid#s $s 'it" t"# &apa%i(it+ of startin) t"# #0#&$tion of on# pro)ram from 'it"in anot"#r pro)ram. !"# first pro)ram is &a((#d t"# par#nt pro&#ss and t"# s#&ond pro)ram t"at )#ts &a((#d from 'it"in t"# first pro)ram is &a((#d a &"i(d pro&#ss. 9n&# t"# s#&ond pro)ram starts #0#&$tion, t"# first is p$t on "o(d $nti( t"# s#&ond pro)ram &omp(#t#s #isit

http!""www.downloadmela.com"

for more papers

#0#&$tion. !"# first pro)ram is t"#n r#start#d. !"# fo((o'in) pro)ram d#monstrat#s $s# of spa'n(( ) f$n&tion. I1 N$(t.& 1I int main ( int ar)&, &"ar1 ar)v[ ] ) { int a[3], i, r#t ; if ( ar)& C 3 PP ar)& D 3 ) { printf ( "!oo man+ or !oo f#' ar)$m#nts..." ) ; #0it ( 0 ) ; } for ( i = 1 ; i C ar)& ; i++ ) a[i] = atoi ( ar)v[i] ) ; r#t = a[1] 1 a[/] ; r#t$rn r#t ; } I1 ,pa'n.& 1I Bin&($d# Cpro&#ss."D Bin&($d# Cstdio."D main( ) { int va( ; va( = spa'n( ( QRSA*!, "< HHN$(t.#0#", "3", "10", "/0", 3@:: ) ; printf ( "HnT#t$rn#d va($# is %d", va( ) ; } 2#r#, t"#r# ar# t'o pro)rams. !"# pro)ram 4N$(t.#0#4 'or6s as a &"i(d pro&#ss '"#r#as 4,pa'n.#0#4 'or6s as a par#nt pro&#ss. 9n #0#&$tion of 4,pa'n.#0#4 it invo6#s 4N$(t.#0#4 and pass#s t"# &ommand.(in# ar)$m#nts to it. 4N$(t.#0#4 in t$rn on #0#&$tion, &a(&$(at#s t"# prod$&t of 10 and /0 and r#t$rns t"# va($# to va( in 4,pa'n.#0#4. *n o$r &a(( to spa'n(( ) f$n&tion, '# "av# pass#d ; param#t#rs, QRSA*! as t"# mod# of #0#&$tion, pat" of 4.#0#4 fi(# to r$n as &"i(dpro&#ss, tota( n$m%#r of ar)$m#nts to %# pass#d to t"# &"i(d pro&#ss, (ist of &ommand (in# ar)$m#nts and 3@::. QRSA*! 'i(( &a$s# o$r app(i&ation to fr##-# #0#&$tion $nti( t"# &"i(d pro&#ss "as &omp(#t#d its #0#&$tion. !"is param#t#r n##ds to %# pass#d as t"# d#fa$(t param#t#r if +o$ ar# 'or6in) $nd#r 89,. $nd#r ot"#r op#ratin) s+st#ms t"at s$pport m$(titas6in), t"is param#t#r &an %# QR39SA*! or QR9AGT:AU. QR39SA*! 'i(( &a$s# t"# par#ntpro&#ss to #0#&$t# a(on) 'it" t"# &"i(d pro&#ss, QR9AGT:AU 'i(( (oad t"# &"i(d pro&#ss on top of t"# par#nt pro&#ss in t"# m#mor+. ................................................................................................. O. #isit

http!""www.downloadmela.com"

for more papers

$re the following two statements identical? &"ar str[;] = "Li&it" ; &"ar 1str = "Li&it" ; Ans 3o5 Arra+s ar# not point#rs. An arra+ is a sin)(#, pr#.a((o&at#d &"$n6 of &onti)$o$s #(#m#nts (a(( of t"# sam# t+p#), fi0#d in si-# and (o&ation. A point#r on t"# ot"#r "and, is a r#f#r#n&# to an+ data #(#m#nt (of a parti&$(ar t+p#) (o&at#d an+'"#r#. A point#r m$st %# assi)n#d to point to spa&# a((o&at#d #(s#'"#r#, %$t it &an %# r#assi)n#d an+ tim#. !"# arra+ d#&(aration &"ar str[;] ; r#K$#sts t"at spa&# for ; &"ara&t#rs %# s#t asid#, to %# 6no'n %+ nam# str. *n ot"#r 'ords t"#r# is a (o&ation nam#d str at '"i&" si0 &"ara&t#rs ar# stor#d. !"# point#r d#&(aration &"ar 1str ; on t"# ot"#r "and, r#K$#sts a p(a&# t"at "o(ds a point#r, to %# 6no'n %+ t"# nam# str. !"is point#r &an point a(most an+'"#r# to an+ &"ar, to an+ &onti)$o$s arra+ of &"ars, or no'"#r#. ................................................................................................. 10. s the following code fragment correct? &onst int 0 = 10 ; int arr[0] ; Ans 3o5 2#r#, t"# varia%(# 0 is first d#&(ar#d as an int so m#mor+ is r#s#rv#d for it. !"#n it is K$a(ifi#d %+ a &onst K$a(ifi#r. 2#n&#, &onst K$a(ifi#d o%M#&t is not a &onstant f$((+. *t is an o%M#&t 'it" r#ad on(+ attri%$t#, and in <, an o%M#&t asso&iat#d 'it" m#mor+ &annot %# $s#d in arra+ dim#nsions. 11. How do write code to retrieve current date and time from the system and display it as a string? Ans @s# tim#( ) f$n&tion to )#t &$rr#nt dat# and tim# and t"#n &tim#( ) f$n&tion to disp(a+ it as a strin). !"is is s"o'n in fo((o'in) &od# snipp#t. Bin&($d# Cs+sHt+p#s."D void main( ) { tim#Rt &$rtim# ; &"ar &tm[?0] ; tim# ( J&$rtim# ) ; IIr#tri#v#s &$rr#nt tim# J stor#s in &$rtim# printf ( "Hn<$rr#nt 8at# J !im# %s", &tim# ( J&$rtim# ) ) ; } #isit

http!""www.downloadmela.com"

for more papers

................................................................................................. 1/. How do change the type of cursor and hide a cursor? Ans S# &an &"an)# t"# &$rsor t+p# %+ $sin) f$n&tion Rs#t&$rsort+p#( ). !"is f$n&tion &an &"an)# t"# &$rsor t+p# to so(id &$rsor and &an #v#n "id# a &$rsor. Fo((o'in) &od# s"o's "o' to &"an)# t"# &$rsor t+p# and "id# &$rsor. Bin&($d# C&onio."D main( ) { I1 2id# &$rsor 1I Rs#t&$rsort+p# ( R39<@T,9T ) ; I1 <"an)# &$rsor to a so(id &$rsor 1I Rs#t&$rsort+p# ( R,9:*8<@T,9T ) ; I1 <"an)# %a&6 to t"# norma( &$rsor 1I Rs#t&$rsort+p# ( R39TNA:<@T,9T ) ; } ................................................................................................. 13. How do write code that would get error number and display error message if any standard error occurs? Ans Fo((o'in) &od# d#monstrat#s t"is. Bin&($d# Cstdio."D Bin&($d# Cstd(i%."D Bin&($d# C#rrno."D main( ) { &"ar 1#rrms) ; F*:G 1fp ; fp = fop#n ( "< Hfi(#.t0t", "r" ) ; if ( fp == 3@:: ) { #rrms) = str#rror ( #rrno ) ; printf ( "Hn%s", #rrms) ) ; } } 2#r#, '# ar# tr+in) to op#n 4fi(#.t0t4 fi(#. 2o'#v#r, if t"# fi(# do#s not #0ist, t"#n it 'o$(d &a$s# #isit

http!""www.downloadmela.com"

for more papers

an #rror. As a r#s$(t, a va($# (in t"is &as# /) r#(at#d to t"# #rror )#n#rat#d 'o$(d )#t s#t in #rrno. #rrno is an #0t#rna( int varia%(# d#&(ar#d in 4std(i%."4 and a(so in 4#rrno."4. 3#0t, '# "av# &a((#d st#rror( ) f$n&tion '"i&" ta6#s an #rror n$m%#r and r#t$rns a point#r to standard #rror m#ssa)# r#(at#d to t"# )iv#n #rror n$m%#r. ................................................................................................. 17. How do write code to get the current drive as well as set the current drive? Ans !"# f$n&tion )#tdis6( ) r#t$rns t"# driv# n$m%#r of &$rr#nt driv#. !"# driv# n$m%#r 0 indi&at#s 4A4 as t"# &$rr#nt driv#, 1 as 4E4 and so on. !"# ,#tdis6( ) f$n&tion s#ts t"# &$rr#nt driv#. !"is f$n&tion ta6#s on# ar)$m#nt '"i&" is an int#)#r indi&atin) t"# driv# to %# s#t. Fo((o'in) pro)ram d#monstrat#s $s# of %ot" t"# f$n&tions. Bin&($d# Cdir."D main( ) { int dno, ma0dr ; dno = )#tdis6( ) ; printf ( "Hn!"# &$rr#nt driv# is %&Hn", ;? + dno ); ma0dr = s#tdis6 ( 3 ) ; dno = )#tdis6( ) ; printf ( "Hn3o' t"# &$rr#nt driv# is %&Hn", ;? + dno ) ; } ................................................................................................. 1?. The functions memcmp" # and memicmp" # !"# f$n&tions m#m&mp( ) and m#mi&mp( ) &ompar#s first n %+t#s of )iv#n t'o %(o&6s of m#mor+ or strin)s. 2o'#v#r, m#m&mp( ) p#rforms &omparison as $nsi)n#d &"ars '"#r#as m#mi&mp( ) p#rforms &omparison as &"ars %$t i)nor#s &as# (i.#. $pp#r or (o'#r &as#). Eot" t"# f$n&tions r#t$rn an int#)#r va($# '"#r# 0 indi&at#s t"at t'o m#mor+ %$ff#rs &ompar#d ar# id#nti&a(. *f t"# va($# r#t$rn#d is )r#at#r t"an 0 t"#n it indi&at#s t"at t"# first %$ff#r is %i))#r t"an t"# s#&ond on#. !"# va($# (#ss t"an 0 indi&at# t"at t"# first %$ff#r is (#ss t"an t"# s#&ond %$ff#r. !"# fo((o'in) &od# snipp#t d#monstrat#s $s# of %ot" Bin&($d# Cstdio."D Bin&($d# Cm#m."D main( ) #isit

http!""www.downloadmela.com"

for more papers

{ &"ar str1[] = "!"is strin) &ontains som# &"ara&t#rs" ; &"ar str/[] = "t"is strin) &ontains" ; int r#s$(t ; r#s$(t = m#m&mp ( str1, str/, str(#n ( str/ ) ) ; printf ( "HnT#s$(t aft#r &omaprin) %$ff#r $sin) m#m&mp( )" ) ; s"o' ( r#s$(t ) ; r#s$(t = m#mi&mp ( str1, str/, str(#n ( str/ ) ) ; printf ( "HnT#s$(t aft#r &omaprin) %$ff#r $sin) m#mi&mp( )" ) ; s"o' ( r#s$(t ) ; } s"o' ( int r ) { if ( r == 0 ) printf ( "Hn!"# %$ff#r str1 and str/ "o(d id#nti&a( data" ) ; if ( r D 0 ) printf ( "Hn!"# %$ff#r str1 is %i))#r t"an %$ff#r str/" ) ; if ( r C 0 ) printf ( "Hn!"# %$ff#r str1 is (#ss t"an %$ff#r str/" ) ; } ................................................................................................. 1;. How do write code to find an amount of free disk space available on current drive? Ans @s# )#tdfr##( ) f$n&tion as s"o'n in fo((o' &od#. Bin&($d# Cstdio."D Bin&($d# Cstd(i%."D Bin&($d# Cdir."D Bin&($d# Cdos."D main( ) { int dr ; str$&t dfr## dis6 ; (on) fr##sp ; #isit

http!""www.downloadmela.com"

for more papers

dr = )#tdis6( ) ; )#tdfr## ( dr + 1 , Jdis6 ) ; if ( dis6.dfRs&($s == 00FFFF ) { printf ( "Hn)#tdfr##( ) f$n&tion fai(#dHn"); #0it ( 1 ) ; } fr##sp = ( (on) ) dis6.dfRavai( 1 ( (on) ) dis6.dfR%s#& 1 ( (on) ) dis6.dfRs&($s ; printf ( "Hn!"# &$rr#nt driv# %& "as %(d %+t#s avai(a%(# as fr## spa&#Hn", 4A4 + dr, fr##sp ) ; } 1=. @s# of arra+ indi&#s... *f '# 'is" to stor# a &"ara&t#r in a &"ar varia%(# &" and t"# &"ara&t#r to %# stor#d d#p#nds on t"# va($# of anot"#r varia%(# sa+ &o(or (of t+p# int), t"#n t"# &od# 'o$(d %# as s"o'n %#(o' s'it&" ( &o(or ) { &as# 0 &" = 4T4 ; %r#a6 ; &as# 1 &" = 4V4 ; %r#a6 ; &as# / &" = 4E4 ; %r#a6 ; } *n p(a&# of s'it&".&as# '# &an ma6# $s# of t"# va($# in &o(or as an ind#0 for a &"ara&t#r arra+. 2o' to do t"is is s"o'n in fo((o'in) &od# snipp#t. &"ar 1str = "TVE4 ; &"ar &" ; int &o(or ; II &od# &" = str[ &o(or ] ; ................................................................................................. 1>. #isit

http!""www.downloadmela.com"

for more papers

F$n&tion at#0it( ) r#&#vi#s param#t#r as t"# addr#ss of f$n&tion of t"# t+p# void f$n ( void ). !"# f$n&tion '"os# addr#ss is pass#d to at#0it( ) )#ts &a((#d %#for# t"# t#rmination of pro)ram. *f at#0it( ) is &a((#d for mor# t"an on# f$n&tion t"#n t"# f$n&tions ar# &a((#d in "first in (ast o$t" ord#r. Uo$ &an v#rif+ t"at from t"# o$tp$t. Bin&($d# Cstdio."D Bin&($d# Cstd(i%."D void f$n1( ) { printf("*nsid# f$n1Hn"); } void f$n/( ) { printf("*nsid# f$n/Hn"); } main( ) { at#0it ( f$n1 ) ; I1 som# &od# 1I at#0it ( f$n/ ) ; printf ( "!"is is t"# (ast stat#m#nt of pro)ramWHn" ); } ................................................................................................. 1O. How do write a user%defined function& which deletes each character in a string str'& which matches any character in string str(? Ans !"# f$n&tion is as s"o'n %#(o' <ompr#ss ( &"ar str1[], &"ar str/[] ) { int i, M, 6 ; for ( i = 6 = 0 ; str1[i] 5= XH0Y ; i++ ) { for ( M = 0 ; str/[M] 5= XH0Y JJ str/[M] 5= str1[i] ; M++ ) ; if ( str/[M] == XH0Y ) str1[6++] = str1[*] ; #isit

http!""www.downloadmela.com"

for more papers

} str1[6] = XH0Y } ................................................................................................. /0. How does free" # know how many bytes to free? Ans !"# ma((o&( ) I fr##( ) imp(#m#ntation r#m#m%#rs t"# si-# of #a&" %(o&6 a((o&at#d and r#t$rn#d, so it is not n#&#ssar+ to r#mind it of t"# si-# '"#n fr##in). ................................................................................................. /1. What is the use of randomi)e" # and srand" # function? Ans S"i(# )#n#ratin) random n$m%#rs in a pro)ram, som#tim#s '# r#K$ir# to &ontro( t"# s#ri#s of n$m%#rs t"at random n$m%#r )#n#rator &r#at#s. !"# pro&#ss of assi)nin) t"# random n$m%#r )#n#rators startin) n$m%#r is &a((#d s##din) t"# )#n#rator. !"# randomi-#( ) and srand( ) f$n&tions ar# $s#d to s##d t"# random n$m%#r )#n#rators. !"# randomi-#( ) f$n&tion $s#s Q<4s &(o&6 to prod$&# a random s##d, '"#r#as t"# srand( ) f$n&tion a((o's $s to sp#&if+ t"# random n$m%#r )#n#rator4s startin) va($#. ................................................................................................. //. How do determine amount of memory currently available for allocating? Ans S# &an $s# f$n&tion &or#(#ft( ) to )#t t"# amo$nt of m#mor+ avai(a%(# for a((o&ation. 2o'#v#r, t"is f$n&tion do#s not )iv# an #0a&t amo$nt of $n$s#d m#mor+. *f, '# ar# $sin) a sma(( m#mor+ mod#(, &or#(#ft( ) r#t$rns t"# amo$nt of $n$s#d m#mor+ %#t'##n t"# top of t"# "#ap and sta&6. *f '# ar# $sin) a (ar)#r mod#(, t"is f$n&tion r#t$rns t"# amo$nt of m#mor+ %#t'##n t"# "i)"#st a((o&at#d m#mor+ and t"# #nd of &onv#ntiona( m#mor+. !"# f$n&tion r#t$rns amo$nt of m#mor+ in t#rms of %+t#s. ................................................................................................. /3. How does a * program come to know about command line arguments? Ans S"#n '# #0#&$t# o$r < pro)ram, op#ratin) s+st#m (oads t"# pro)ram into m#mor+. *n &as# of 89,, it first (oads /?; %+t#s into m#mor+, &a((#d pro)ram s#)m#nt pr#fi0. !"is &ontains fi(# ta%(#, #nvironm#nt s#)m#nt, and &ommand (in# information. S"#n '# &ompi(# t"# < pro)ram t"# &ompi(#r ins#rts additiona( &od# t"at pars#s t"# &ommand, assi)nin) it to t"# ar)v arra+, ma6in) t"# ar)$m#nts #asi(+ a&&#ssi%(# 'it"in o$r < pro)ram.

#isit

http!""www.downloadmela.com"

for more papers

/7. When we open a file& how does functions like fread" #+fwrite" #& etc. get to know from where to read or to write the data? Ans S"#n '# op#n a fi(# for r#adI'rit# op#ration $sin) f$n&tion (i6# fop#n( ), it r#t$rns a point#r to t"# str$&t$r# of t+p# F*:G. !"is str$&t$r# stor#s t"# fi(# point#r &a((#d position point#r, '"i&" 6##ps tra&6 of &$rr#nt (o&ation 'it"in t"# fi(#. 9n op#nin) fi(# for r#adI'rit# op#ration, t"# fi(# point#r is s#t to t"# start of t"# fi(#. Ga&" tim# '# r#adI'rit# a &"ara&t#r, t"# position point#r advan&#s on# &"ara&t#r. *f '# r#ad on# (in# of t#0t at a st#p from t"# fi(#, t"#n fi(# point#r advan&#s to t"# start of t"# n#0t (in#. *f t"# fi(# is op#n#d in app#nd mod#, t"# fi(# point#r is p(a&#d at t"# v#r+ #nd of t"# fi(#. @sin) fs##6( )f$n&tion '# &an s#t t"# fi(# point#r to som# ot"#r p(a&# 'it"in t"# fi(#. .................................................................................................

/?. The si)eof" # function doesn,t return the si)e of the block of memory pointed to by a pointer. Why? Ans !"# si-#of( ) op#rator do#s not 6no' t"at ma((o&( ) "as %##n $s#d to a((o&at# a point#r. si-#of( ) )iv#s $s t"# si-# of point#r its#(f. !"#r# is no "and+ 'a+ to find o$t t"# si-# of a %(o&6 a((o&at#d %+ ma((o&( ). ................................................................................................. /;. -./!E0 $nd -./1--2 ,om#tim#s '"i(# 'or6in) 'it" far point#rs '# n##d to %r#a6 a far addr#ss into its s#)m#nt and offs#t. *n s$&" sit$ations '# &an $s# FQR,GV and FQR9FF ma&ros. Fo((o'in) pro)ram i(($strat#s t"# $s# of t"#s# t'o ma&ros. Bin&($d# Cdos."D main( ) { $nsi)n#d s, o ; &"ar far 1ptr = "2#((o5" ; s = FQR,GV ( ptr ) ; o = FQR9FF ( ptr ) ; printf ( "Hn%$ %$", s, o ) ; } ................................................................................................. /=.

#isit

http!""www.downloadmela.com"

for more papers

How do write a program to convert a string containing number in a he3adecimal form to its e4uivalent decimal? Ans !"# fo((o'in) pro)ram d#monstrat#s t"is main( ) { &"ar str[] = "0AE" ; int ", "#0, i, n ; n=0;"=1; for ( i = 0 ; " == 1 ; i++ ) { if ( str[i] D= 404 JJ str[i] C= 4O4 ) "#0 = str[i] . 404 ; #(s# { if ( str[i] D= 4a4 JJ str[i] C= 4f4 ) "#0 = str[i] . 4a4 + 10 ; #(s# if ( str[i] D= 4A4 JJ str[i] C= 4F4 ) "#0 = str[i] . 4A4 + 10 ; #(s# "=0; } if ( " == 1 ) n = 1; 1 n + "#0 ; } printf ( "Hn!"# d#&ima( #K$iva(#nt of %s is %d", str, n ) ; } !"# o$tp$t of t"is pro)ram 'o$(d %# t"# d#&ima( #K$iva(#nt of 0AE is 1=1. ................................................................................................. />. How do write code that reads the segment register settings? Ans S# &an $s# s#)r#ad( ) f$n&tion to r#ad s#)m#nt r#)ist#r s#ttin)s. !"#r# ar# fo$r s#)m#nt r#)ist#rsZ&od# s#)m#nt, data s#)m#nt, sta&6 s#)m#nt and #0tra s#)m#nt. ,om#tim#s '"#n '# $s# 89, and E*9, s#rvi&#s in apro)ram '# n##d to 6no' t"# s#)m#nt r#)ist#r4s va($#. *n s$&" a sit$ation '# &an $s# s#)r#ad( ) f$n&tion. !"# fo((o'in) pro)ram i(($strat#s t"# $s# of t"is f$n&tion. Bin&($d# Cdos."D main( ) { str$&t ,TGV, s ; s#)r#ad ( Js ) ; printf ( "Hn<, %[ 8, %[ ,, %[ G, %[",s.&s, s.ds, s.ss, s.#s ) ; #isit

http!""www.downloadmela.com"

for more papers

} ................................................................................................. /O. What is environment and how do get environment for a specific entry? Ans S"i(# 'or6in) in 89,, it stor#s information in a m#mor+ r#)ion &a((#d #nvironm#nt. *n t"is r#)ion '# &an p(a&# &onfi)$ration s#ttin)s s$&" as &ommand pat", s+st#m prompt, #t&. ,om#tim#s in apro)ram '# n##d to a&&#ss t"# information &ontain#d in #nvironm#nt. !"# f$n&tion )#t#nv( ) &an %# $s#d '"#n '# 'ant to a&&#ss #nvironm#nt for a sp#&ifi& #ntr+. Fo((o'in) pro)ram d#monstrat#s t"# $s# of t"is f$n&tion. Bin&($d# Cstdio."D Bin&($d# Cstd(i%."D main( ) { &"ar 1pat" = 3@:: ; pat" = )#t#nv ( "QA!2" ) ; if ( 1pat" 5= 3@:: ) printf ( "HnQat" %s", pat" ) ; #(s# printf ( "HnQat" is not s#t" ) ; } ................................................................................................. 30. How do display current date in the format given below? ,at$rda+ 9&to%#r 1/, /00/ Ans Fo((o'in) pro)ram i(($strat#s "o' '# &an disp(a+ dat# in a%ov# )iv#n format. Bin&($d# Cstdio."D Bin&($d# Ctim#."D main( ) { str$&t tm 1&$rtim# ; tim#Rt dtim# ; &"ar str[30] ; tim# ( Jdtim# ) ; &$rtim# = (o&a(tim# ( Jdtim# ) ; strftim# ( str, 30, "%A %E %d, %U", &$rtim# ) ; #isit

http!""www.downloadmela.com"

for more papers

printf ( "Hn%s", str ) ; } 2#r# '# "av# &a((#d tim#( ) f$n&tion '"i&" r#t$rns &$rr#nt tim#. !"is tim# is r#t$rn#d in t#rms of s#&onds, #(aps#d sin&# 00 00 00 VN!, \an$ar+ 1, 1O=0. !o #0tra&t t"# '##6 da+, da+ of mont", #t&. from t"is va($# '# n##d to %r#a6 do'n t"# va($# to a tm str$&t$r#. !"is is don# %+ t"#f$n&tion (o&a(tim#( ). !"#n '# "av# &a((#d strftim#( ) f$n&tion to format t"# tim# and stor# it in a strin) str. 31. f we have declared an array as global in one file and we are using it in another file then why doesn't the si)eof operator works on an e3tern array? Ans An #0t#rn arra+ is of in&omp(#t# t+p# as it do#s not &ontain t"# si-#. 2#n&# '# &annot $s# si-#of op#rator, as it &annot )#t t"# si-# of t"# arra+ d#&(ar#d in anot"#r fi(#. !o r#so(v# t"is $s# an+ of on# t"# fo((o'in) t'o so($tions 1. *n t"# sam# fi(# d#&(ar# on# mor# varia%(# t"at "o(ds t"# si-# of arra+. For #0amp(#, arra+.& int arr[?] ; int arrs- = si-#of ( arr ) ; m+pro).& #0t#rn int arr[] ; #0t#rn int arrs- ; /. 8#fin# a ma&ro '"i&" &an %# $s#d in an arra+ d#&(aration. For #0amp(#, m+"#ad#r." Bd#fin# ,] ? arra+.& Bin&($d# "m+"#ad#r."" int arr[,]] ; m+pro).& Bin&($d# "m+"#ad#r."" #0t#rn int arr[,]] ; ................................................................................................. #isit

http!""www.downloadmela.com"

for more papers

3/. How do write printf" # so that the width of a field can be specified at runtime? Ans !"is is s"o'n in fo((o'in) &od# snipp#t. main( ) { int ', no ; printf ( "Gnt#r n$m%#r and t"# 'idt" for t"# n$m%#r fi#(d " ) ; s&anf ( "%d%d", Jno, J' ) ; printf ( "%1d", ', no ) ; } 2#r#, an 414 in t"# format sp#&ifi#r in printf( ) indi&at#s t"at an int va($# from t"# ar)$m#nt (ist s"o$(d %# $s#d for t"# fi#(d 'idt". ................................................................................................. 33. How to find the row and column dimension of a given (%5 array? Ans S"#n#v#r '# initia(i-# a /.8 arra+ at t"# sam# p(a&# '"#r# it "as %##n d#&(ar#d, it is not n#&#ssar+ to m#ntion t"# ro' dim#nsion of an arra+. !"# ro' and &o($mn dim#nsions of s$&" an arra+ &an %# d#t#rmin#d pro)rammati&a((+ as s"o'n in fo((o'in)pro)ram. void main( ) { int a[][3] = { 0, 1, /, O,.;, >, =, ?, 77, /3, 11,1? } ; int & = si-#of ( a[0] ) I si-#of ( int ) ; int r = ( si-#of ( a ) I si-#of ( int ) ) I & ; int i, M ; printf ( "HnTo' %dHn<o( %dHn", r, & ) ; for ( i = 0 ; i C r ; i++ ) { for ( M = 0 ; M C & ; M++ ) printf ( "%d ", a[i][M] ) ; printf ( "Hn" ) ; } } ................................................................................................. #isit

http!""www.downloadmela.com"

for more papers

37. The access" # function... !"# a&&#ss( ) f$n&tion &"#&6s for t"# #0ist#n&# of a fi(# and a(so d#t#rmin#s '"#t"#r it &an %# r#ad, 'ritt#n to or #0#&$t#d. !"is f$n&tion ta6#s t'o ar)$m#nts t"# fi(#nam# and an int#)#r indi&atin) t"# a&&#ss mod#. !"# va($#s ;, 7, /, and 1 &"#&6s for r#adI'rit#, r#ad, 'rit# and #0#&$t# p#rmission of a )iv#n fi(#, '"#r#as va($# 0 &"#&6s '"#t"#r t"# fi(# #0ists or not. Fo((o'in)pro)ram d#monstrat#s "o' '# &an $s# a&&#ss( ) f$n&tion to &"#&6 if a )iv#n fi(# #0ists. Bin&($d# Cio."D main( ) { &"ar fnam#[;=] ; printf ( "HnGnt#r nam# of fi(# to op#n" ) ; )#ts ( fnam# ) ; if ( a&&#ss ( fnam#, 0 ) 5= 0 ) { printf ( "HnFi(# do#s not #0ist." ) ; r#t$rn ; } } ................................................................................................. 3?. How do convert a floating%point number to a string? Ans @s# f$n&tion )&vt( ) to &onv#rt a f(oatin).point n$m%#r to a strin). Fo((o'in) pro)ram d#monstrat#s t"# $s# of t"is f$n&tion. Bin&($d# Cstd(i%."D main( ) { &"ar str[/?] ; f(oat no ; int d) = ? ; I1 si)nifi&ant di)its 1I no = 17.3/1; ; )&vt ( no, d), str ) ; printf ( ",trin) %sHn", str ) ; } #isit

http!""www.downloadmela.com"

for more papers

3;. What is a stack ? Ans !"# sta&6 is a r#)ion of m#mor+ 'it"in '"i&" o$r pro)rams t#mporari(+ stor# data as t"#+ #0#&$t#. For #0amp(#, '"#n a pro)ram pass#s param#t#rs to f$n&tions, < p(a&#s t"# param#t#rs on t"# sta&6. S"#n t"# f$n&tion &omp(#t#s, < r#mov#s t"# it#ms from t"# sta&6. ,imi(ar(+, '"#n a f$n&tion d#&(ar#s (o&a( varia%(#s, < stor#s t"# varia%(#4s va($#s on t"# sta&6 d$rin) t"# f$n&tion4s #0#&$tion. 8#p#ndin) on t"# pro)ram4s $s# of f$n&tions and param#t#rs, t"# amo$nt of sta&6 spa&# t"at a pro)ram r#K$ir#s 'i(( diff#r. ................................................................................................. 3=. A((o&atin) m#mor+ for a 3.8 arra+ Bin&($d# "a((o&."" Bd#fin# NA[[ 3 Bd#fin# NA[U 7 Bd#fin# NA[] ? main( ) { int 111p, i, M, 6 ; p = ( int 111 ) ma((o& ( NA[[ 1 si-#of ( int 11 ) ) ; for ( i = 0 ; i C NA[[ ; i++ ) { p[i] = ( int 11 ) ma((o& ( NA[U 1 si-#of ( int 1 ) ) ; for ( M = 0 ; M C NA[U ; M++ ) p[i][M] = ( int 1 ) ma((o& ( NA[] 1 si-#of ( int ) ) ; } for ( 6 = 0 ; 6 C NA[] ; 6++ ) { for ( i = 0 ; i C NA[[ ; i++ ) { for ( M = 0 ; M C NA[U ; M++ ) { p[i][M][6] = i + M + 6 ; printf ( "%d ", p[i][M][6] ) ; } printf ( "Hn" ) ; } printf ( "HnHn" ) ; } } 8ata ,tr$&t$r#s 2o' to distin)$is" %#t'##n a %inar+ tr## and a tr##W Ans A nod# in a tr## &an "av# an+ n$m%#r of %ran&"#s. S"i(# a %inar+ tr## is a tr## #isit

http!""www.downloadmela.com"

for more papers

str$&t$r# in '"i&" an+ nod# &an "av# at most t'o %ran&"#s. For %inar+ tr##s '# distin)$is" %#t'##n t"# s$%tr## on t"# (#ft and s$%tr## on t"# ri)"t, '"#r#as for tr##s t"# ord#r of t"# s$%tr##s is irr#(#vant. <onsid#r t"# fo((o'in) fi)$r#... !"is a%ov# fi)$r# s"o's t'o %inar+ tr##s, %$t t"#s# %inar+ tr##s ar# diff#r#nt. !"# first "as an #mpt+ ri)"t s$%tr## '"i(# t"# s#&ond "as an #mpt+ (#ft s$%tr##. *f t"# a%ov# ar# r#)ard#d as tr##s (not t"# %inar+ tr##s), t"#n t"#+ ar# sam# d#spit# t"# fa&t t"at t"#+ ar# dra'n diff#r#nt(+. A(so, an #mpt+ %inar+ tr## &an #0ist, %$t t"#r# is no tr## "avin) -#ro nod#s. ................................................................................................. 3>. How do use the function lde3p" # in a program? Ans !"# mat" f$n&tion (d#0p( ) is $s#d '"i(# so(vin) t"# &omp(#0 mat"#mati&a( #K$ations. !"is f$n&tion ta6#s t'o ar)$m#nts, a do$%(# va($# and an int r#sp#&tiv#(+. !"# ord#r in '"i&" (d#0p( ) f$n&tion p#rforms &a(&$(ations is ( n 1 po' ( /, #0p ) ) '"#r# n is t"# do$%(# va($# and #0p is t"# int#)#r. !"# fo((o'in) pro)ram d#monstrat#s t"# $s# of t"is f$n&tion. Bin&($d# Cstdio."D Bin&($d# Cmat"."D void main( ) { do$%(# ans ; do$%(# n = 7 ; ans = (d#0p ( n, / ) ; printf ( "Hn!"# (d#0p va($# is %(fHn", ans ) ; } 2#r#, (d#0p( ) f$n&tion 'o$(d )#t #0pand#d as ( 7 1 / 1 / ), and t"# o$tp$t 'o$(d %# t"# (d#0p va($# is 1;.000000 ................................................................................................. 3O. *an we get the mantissa and e3ponent form of a given number? Ans !"# f$n&tion fr#0p( ) sp(its t"# )iv#n n$m%#r into a mantissa and #0pon#nt form. !"# f$n&tion ta6#s t'o ar)$m#nts, t"# n$m%#r to %# &onv#rt#d as a do$%(# va($# and an int to stor# t"# #0pon#nt form. !"# f$n&tion r#t$rns t"# mantissa part as a do$%(# va($#. Fo((o'in) #0amp(# d#monstrat#s t"# $s# of t"is f$n&tion. Bin&($d# Cmat"."D Bin&($d# Cstdio."D void main( ) { #isit

http!""www.downloadmela.com"

for more papers

do$%(# mantissa, n$m%#r ; int #0pon#nt ; n$m%#r = >.0 ; mantissa = fr#0p ( n$m%#r, J#0pon#nt ) ; printf ( "!"# n$m%#r %(f is ", n$m%#r ) ; printf ( "%(f tim#s t'o to t"# ", mantissa ) ; printf ( "po'#r of %dHn", #0pon#nt ) ; r#t$rn 0 ; } ................................................................................................. 70. How do write code that e3ecutes certain function only at program termination? Ans @s# at#0it( ) f$n&tion as s"o'n in fo((o'in) pro)ram. Bin&($d# Cstd(i%."D main( ) { int &" ; void f$n ( void ) ; at#0it ( f$n ) ; II &od# } void f$n( void ) { printf ( "Hn!#rminat# pro)ram......" ) ; )#t&"( ) ; } ................................................................................................. 71. What are memory models? Ans !"# &ompi(#r $s#s a m#mor+ mod#( to d#t#rmin# "o' m$&" m#mor+ is a((o&at#d to t"# pro)ram. !"# Q< divid#s m#mor+ into %(o&6s &a((#d s#)m#nts of si-# ;7 LE. @s$a((+, pro)ram $s#s on# s#)m#nt for &od# and a s#&ond s#)m#nt for data. A m#mor+ mod#( d#fin#s t"# n$m%#r of s#)m#nts t"# &ompi(#r &an $s# for #a&". *t is important to 6no' '"i&" m#mor+ mod#( &an %# $s#d for a pro)ram. *f '# $s# 'ron) m#mor+ mod#(, t"# pro)ram mi)"t not "av# #no$)" m#mor+ to #0#&$t#. !"# pro%(#m &an %# so(v#d $sin) (ar)#r m#mor+ mod#(. 2o'#v#r, (ar)#r t"# m#mor+ mod#(, s(o'#r is +o$r pro)ram #0#&$tion. ,o '# m$st &"oos# t"# sma((#st m#mor+ mod#( t"at satisfi#s o$r pro)ram n##ds. Nost of t"# &ompi(#rs s$pport m#mor+ mod#(s (i6# tin+, sma((, m#di$m, &ompa&t, (ar)# and "$)#. 7/. How does * compiler store elements in a multi%dimensional array? #isit

http!""www.downloadmela.com"

for more papers

Ans !"# &ompi(#r maps m$(ti.dim#nsiona( arra+s in t'o 'a+sZTo' maMor ord#r and <o($mn ord#r. S"#n t"# &ompi(#r p(a&#s #(#m#nts in &o($mns of an arra+ first t"#n it is &a((#d &o($mn. maMor ord#r. S"#n t"# &ompi(#r p(a&#s #(#m#nts in ro's of an arra+ first t"#n it is &a((#d ro'. maMor ord#r. < &ompi(#rs stor# m$(tidim#nsiona( arra+s in ro'.maMor ord#r. For #0amp(#, if t"#r# is a m$(ti.dim#nsiona( arra+ a[/][3], t"#n a&&ordin) ro'.maMor ord#r, t"# #(#m#nts 'o$(d )#t stor#d in m#mor+ fo((o'in) ord#r a[0][0], a[0][1], a[0][/], a[1][0], a[1][1], a[1][/] ................................................................................................. 73. f the result of an /e3pression has to be stored to one of two variables& depending on a condition& can we use conditional operators as shown below? ( ( i C 10 ) W M 6 ) = ( 1 / + p ; Ans 3o5 !"# a%ov# stat#m#nt is inva(id. S# &annot $s# t"# &onditiona( op#rators in t"is fas"ion. !"# &onditiona( op#rators (i6# most op#rators, +i#(ds a va($#, and '# &annot assi)n t"# va($# of an R#0pr#ssion to a va($#. 2o'#v#r, '# &an $s# &onditiona( op#rators as s"o'n in fo((o'in) &od# snipp#t. main( ) { int i, M, 6, ( ; i = ? ; M = 10 ; 6 = 1/, ( = 1 ; 1 ( ( i C 10 ) W JM J6 ) = ( 1 / + 17 ; printf ( "i = %d M = %d 6 = %d ( = %d", i, M, 6, ( ) ; } !"# o$tp$t of t"# a%ov# pro)ram 'o$(d %# as )iv#n %#(o' i = ? M = 1; 6 = 1/ ( = 1 ................................................................................................. 77. How can find the day of the week of a given date? Ans !"# fo((o'in) &od# snipp#t s"o's "o' to )#t t"# da+ of '##6 from t"# )iv#n dat#. da+of'##6 ( int ++, int mm, int dd ) { I1Nonda+ = 1 and ,$nda+ = 0 1I I1 mont" n$m%#r D= 1 and C= 1/, ++ D 1=?/ or so 1I stati& int arr[ ] = { 0, 3, /, ?, 0, 3, ?, 1, 7, ;, /, 7 } ; ++ = ++ . mm C 3 ; r#t$rn ( ++ + ++ I 7 . ++ I 100 + ++ I 700 + arr[ mm . 1] + dd ) % = ; }

#isit

http!""www.downloadmela.com"

for more papers

void main( ) { printf ( "HnHnHn8a+ of '##6 %d ", da+of'##6 ( /00/, ?, 1> ) ) ; } .................................................................................................

7?. What's the difference between these two declarations? str$&t str1 { ... } ; t+p#d#f str$&t { ... } str/ ; Ans !"# first form d#&(ar#s a str$&t$r# ta) '"#r#as t"# s#&ond d#&(ar#s a t+p#d#f. !"# main diff#r#n&# is t"at t"# s#&ond d#&(aration is of a s(i)"t(+ mor# a%stra&t t+p# .. its $s#rs don4t n#&#ssari(+ 6no' t"at it is a str$&t$r#, and t"# 6#+'ord str$&t is not $s#d '"#n d#&(arin) instan&#s of it. ................................................................................................. 7;. How do print the contents of environment variables? Ans . !"# fo((o'in) pro)ram s"o's "o' to a&"i#v# t"is main( int ar)&, &"ar 1ar)v[ ], &"ar 1#nv[ ] ) { int i = 0 ; &(rs&r( ) ; '"i(# ( #nv[ i ] ) printf ( "Hn%s", #nv[ i++ ] ) ; } main( ) "as t"# t"ird &ommand (in# ar)$m#nt #nv, '"i&" is an arra+ of point#rs to t"# strin)s. Ga&" point#r points to an #nvironm#nt varia%(# from t"# (ist of #nvironm#nt varia%(#s. ................................................................................................. 7=.7>. What would the second and the third printf" # output the following program? main( ) { &"ar 1str[ ] = { "Vood Nornin)" "Vood Gv#nin)" "Vood Aft#rnoon" #isit

http!""www.downloadmela.com"

for more papers

}; printf ( "HnFirst strin) = %s", str[0] ) ; printf ( "Hn,#&ond strin) = %s", str[1] ) ; printf ( "Hn!"ird strin) = %s", str[/] ) ; } Ans For t"# a%ov# )iv#n pro)ram, '# #0p#&t t"# o$tp$t as Vood Gv#nin) and Vood Aft#rnoon, for t"# s#&ond and t"ird printf( ). 2o'#v#r, t"# o$tp$t 'o$(d %# as s"o'n %#(o'. First strin) = Vood Nornin)Vood Gv#nin)Vood Aft#rnoon ,#&ond strin) = ( n$(( ) !"ird strin) = S"at is missin) in t"# a%ov# )iv#n &od# snipp#t is a &omma s#parator '"i&" s"o$(d s#parat# t"# strin)s Vood Nornin), Vood Gv#nin) and Vood Aft#rnoon. 9n addin) &omma, '# 'o$(d )#t t"# o$tp$t as s"o'n %#(o'. First strin) = Vood Nornin) ,#&ond strin) = Vood Gv#nin) !"ird strin) = Vood Aft#rnoon ................................................................................................. 7O. How do use scanf" # to read the date in the form 'dd%mm%yy' ? Ans !"#r# ar# t'o 'a+s to r#ad t"# dat# in t"# form of 4dd.mm.++4 on# possi%(# 'a+ is... int dd, mm, ++ ; &"ar &" ; I1 for &"ar 4.4 1I printf ( "HnGnt#r t"# dat# in t"# form of dd.mm.++ " ) ; s&anf( "%d%&%d%&%d", Jdd, J&", Jmm, J&", J++ ) ; And anot"#r %#st 'a+ is to $s# s$ppr#ssion &"ara&t#r 1 as... int dd, mm, ++ ; s&anf( "%d%1&%d%1&%d", Jdd, Jmm, J++ ) ; !"# s$ppr#ssion &"ara&t#r 1 s$ppr#ss#s t"# inp$t r#ad from t"# standard inp$t %$ff#r for t"# assi)n#d &ontro( &"ara&t#r. ................................................................................................. ?0. How do print a floating%point number with higher precision say (6.6789:;67 with only precision up to two decimal places? Ans !"is &an %# a&"i#v#d t"ro$)" t"# $s# of s$ppr#ssion &"ar 414 in t"# format strin) of printf( ) as s"o'n in t"# fo((o'in) pro)ram. main( ) #isit

http!""www.downloadmela.com"

for more papers

{ int i = / ; f(oat f = /3.37?;>=37 ; printf ( "%.1f", i, f ) ; } !"# o$tp$t of t"# a%ov# pro)ram 'o$(d %# /3.3?. ................................................................................................. ?1. $re the e3pressions <ptr== and ==<ptr same? Ans 3o. 1ptr++ in&r#m#nts t"# point#r and not t"# va($# point#d %+ it, '"#r#as ++1ptr in&r#m#nts t"# va($# %#in) point#d to %+ ptr. ................................................................................................. ?/. strpbrk" # !"# f$n&tion strp%r6( ) ta6#s t'o strin)s as param#t#rs. *t s&ans t"# first strin), to find, t"# first o&&$rr#n&# of an+ &"ara&t#r app#arin) in t"# s#&ond strin). !"# f$n&tion r#t$rns a point#r to t"# first o&&$rr#n&# of t"# &"ara&t#r it fo$nd in t"# first strin). !"# fo((o'in) pro)ram d#monstrat#s t"# $s# of strin) f$n&tion strp%r6( ). Bin&($d# Cstrin)."D main( ) { &"ar 1str1 = "2#((o5" ; &"ar 1str/ = "E#tt#r" ; &"ar 1p ; p = strp%r6 ( str1, str/ ) ; if ( p ) printf ( "!"# first &"ara&t#r fo$nd in str1 is %&", 1p ) ; #(s# printf ( "!"# &"ara&t#r not fo$nd" ) ; } !"# o$tp$t of t"# a%ov# pro)ram 'o$(d %# t"# first &"ara&t#r fo$nd in str1 is # div( )... !"# f$n&tion div( ) divid#s t'o int#)#rs and r#t$rns t"# K$oti#nt and r#maind#r. !"is f$n&tion ta6#s t'o int#)#r va($#s as ar)$m#nts; divid#s first int#)#r 'it" t"# s#&ond on# and r#t$rns t"# ans'#r of division of t+p# divRt. !"# data t+p# divRt is a str$&t$r# t"at &ontains t'o (on) ints, nam#(+ K$ot and r#m, '"i&" stor# K$oti#nt and r#maind#r of division r#sp#&tiv#(+. !"# fo((o'in) #0amp(# s"o's t"# $s# of div( ) f$n&tion. #isit

http!""www.downloadmela.com"

for more papers

Bin&($d# Cstd(i%."D void main( ) { divRt r#s ; r#s = div ( 3/, ? ) ; printf ( "Hn!"# K$oti#nt = %d and r#maind#r = %d ", r#s.K$ot, r#s.r#m ) ; ?3. *an we convert an unsigned long integer value to a string? Ans !"# f$n&tion $(toa( ) &an %# $s#d to &onv#rt an $nsi)n#d (on) int#)#r va($# to a strin). !"is f$n&tion ta6#s t"r## ar)$m#nts, first t"# va($# t"at is to %# &onv#rt#d, s#&ond t"# %as# addr#ss of t"# %$ff#r in '"i&" t"# &onv#rt#d n$m%#r "as to %# stor#d ('it" a strin) t#rminatin) n$(( &"ara&t#r 4H04) and t"# (ast ar)$m#nt sp#&ifi#s t"# %as# to %# $s#d in &onv#rtin) t"# va($#. Fo((o'in) #0amp(# d#monstrat#s t"# $s# of t"is f$n&tion. Bin&($d# Cstd(i%."D void main( ) { $nsi)n#d (on) $( = 3/37?;=/31: ; &"ar str[/?] ; $(toa ( $(, str, 10 ) ; printf ( "str = %s $nsi)n#d (on) = %($Hn", str, $( ) ; } ................................................................................................. ?7. ceil" # and floor" # !"# mat" f$n&tion &#i(( ) ta6#s a do$%(# va($# as an ar)$m#nt. !"is f$n&tion finds t"# sma((#st possi%(# int#)#r to '"i&" t"# )iv#n n$m%#r &an %# ro$nd#d $p. ,imi(ar(+, f(oor( ) %#in) a mat" f$n&tion, ta6#s a do$%(# va($# as an ar)$m#nt and r#t$rns t"# (ar)#st possi%(# int#)#r to '"i&" t"# )iv#n do$%(# va($# &an %# ro$nd#d do'n. !"# fo((o'in) pro)ram d#monstrat#s t"# $s# of %ot" t"# f$n&tions. Bin&($d# Cmat"."D void main( ) { do$%(# no = 173=./31;= ; do$%(# do'n, $p ; do'n = f(oor ( no ) ; $p = &#i( ( no ) ; #isit

http!""www.downloadmela.com"

for more papers

printf ( "!"# ori)ina( n$m%#r %=.?(fHn", no ) ; printf ( "!"# n$m%#r ro$nd#d do'n %=.?(fHn", do'n ) ; printf ( "!"# n$m%#r ro$nd#d $p %=.?(fHn", $p ) ; } !"# o$tp$t of t"is pro)ram 'o$(d %#, !"# ori)ina( n$m%#r 173=./31;= !"# n$m%#r ro$nd#d do'n 173=.00000 !"# n$m%#r ro$nd#d $p 173>.00000 ................................................................................................. ??. How do use function ecvt" # in a program? Ans !"# f$n&tion #&vt( ) &onv#rts a f(oatin).point va($# to a n$(( t#rminat#d strin). !"is f$n&tion ta6#s fo$r ar)$m#nts, s$&" as, t"# va($# to %# &onv#rt#d to strin), t"# n$m%#r of di)its to %# &onv#rt#d to strin), and t'o int#)#r point#rs. !"# t'o.int#)#r point#r stor#s t"# position of t"# d#&ima( point (r#(ativ# to t"# strin)) and t"# si)n of t"# n$m%#r, r#sp#&tiv#(+. *f t"# va($# in a varia%(#, $s#d to stor# si)n is 0, t"#n t"# n$m%#r is positiv# and, if it is non. -#ro, t"#n t"# n$m%#r is n#)ativ#. !"# f$n&tion r#t$rns a point#r to t"# strin) &ontainin) di)its. Fo((o'in) pro)ram d#monstrat#s t"# $s# of t"is f$n&tion. Bin&($d# Cstd(i%."D main( ) { &"ar 1str ; do$%(# va( ; int d#&, si)n ; int ndi) = 7 ; va( = // ; str = #&vt ( va(, ndi), Jd#&, Jsi)n ) ; printf ( "strin) = %s d#& = %d si)n = %dHn", str, d#&, si)n ) ; va( = .37?.;= ; ndi) = > ; str = #&vt ( va(, ndi), Jd#&, Jsi)n ) ; printf ( "strin) = %s d#& = %d si)n = %dHn", str, d#&, si)n ) ; II n$m%#r 'it" a s&i#ntifi& notation va( = 3.?7;=1/#? ; ndi) = ? ; str = #&vt ( va(, ndi), Jd#&, Jsi)n ) ; printf ( "strin) = %s d#& = %d si)n = %dHn", str, d#&, si)n ) ; } #isit

http!""www.downloadmela.com"

for more papers

!"# o$tp$t of t"is pro)ram 'o$(d %# strin) = //00 d#& = / si)n = 0 strin) = 37?;=000 d#& = 3 si)n = 1 strin) = 3?7;= d#& = ; si)n = 0 ................................................................................................. ?;. How to run 5 > command programmatically? Ans S# &an $s# t"# s+st#m( ) f$n&tion to #0#&$t# t"# 8*T &ommand a(on) 'it" its options. Fo((o'in) pro)ram s"o's "o' t"is &an %# a&"i#v#d II m+dir.& main ( int ar)&, &"ar 1ar)v[ ] ) { &"ar str[30] ; if ( ar)& C / ) #0it ( 0 ) ; sprintf ( str, "dir %s %s", ar)v[1], ar)v[/] ) ; s+st#m ( str ) ; } *f '# r$n t"# #0#&$ta%(# fi(# of t"is pro)ram at &ommand prompt passin) t"# &ommand (in# ar)$m#nts as fo((o's D m+dir a%&.& Is !"is 'i(( s#ar&" t"# fi(# 4a%&.&4 in t"# &$rr#nt dir#&tor+. ................................................................................................. ?=. !uppose have a structure having fields name& age& salary and have passed address of age to a function fun" #. How can access the other member of the structure using the address of age? Ans str$&t #mp { &"ar nam#[/0] ; int a)# ; #isit

http!""www.downloadmela.com"

for more papers

f(oat sa(ar+ ; }; main( ) { str$&t #mp # ; printf ( "HnGnt#r nam# " ) ; s&anf ( "%s", #.nam# ) ; printf ( "HnGnt#r a)# " ) ; s&anf ( "%d", J#.a)# ) ; printf ( "HnGnt#r sa(ar+ " ) ; s&anf ( "%f", J#.sa(ar+ ) ; f$n ( J#.a)# ) ; } f$n ( int 1p ) { str$&t #mp 1K ; int offs#t ; offs#t = ( &"ar 1 ) ( J ( ( str$&t #mp 1 ) 0 ) .D a)# ) . ( &"ar 1 ) ( ( str$&t #mp1 ) 0 ) ; K = ( str$&t #mp 1 ) ( ( &"ar 1 ) p . offs#t ) ; printf ( "Hnnam# %s", K .D nam# ) ; printf ( "Hna)# %d", K .D a)# ) ; printf ( "Hnsa(ar+ %f", K .D sa(ar+ ) ; } ?>. How to restrict the program's output to a specific screen region? Ans A < f$n&tion 'indo'( ) &an %# $s#d to r#stri&t t"# s&r##n o$tp$t to a sp#&ifi& r#)ion. !"# 'indo'( ) f$n&tion d#fin#s a t#0t.mod# 'indo'. !"# param#t#rs pass#d to t"is f$n&tion d#fin#s t"# $pp#r.(#ft and (o'#r.ri)"t &orn#r of t"# r#)ion 'it"in '"i&" +o$ 'ant t"# o$tp$t. *n t"# fo((o'in)pro)ram , t"# strin) 42#((o54 )#ts print#d 'it"in t"# sp#&ifi#d r#)ion. !o print t"# strin) '# m$st $s# &printf( ) f$n&tion '"i&" prints dir#&t(+ on t"# t#0t.mod# 'indo'. Bin&($d# C&onio."D main( ) { int i, M ; 'indo' ( /0, >, ;0, 1= ) ; for ( i = 0 ; i C > ; i++ ) for ( M = 0 ; M C 10 ; M++ ) &printf ( "2#((o5" ) ; } ................................................................................................. #isit

http!""www.downloadmela.com"

for more papers

?O. !ometimes you need to prompt the user for a password. When the user types in the password& the characters the user enters should not appear on the screen. $ standard library function getpass" # can be used to perform such function. ?a3imum number of characters that can be entered as password is :. main( ) { &"ar 1p'd ; p'd = )#tpass ( "Gnt#r Qass'ord" ) ; if ( str&mp ( p'd, "or)&it+" ) ) printf ( "HnQass'ord %s is in&orr#&t", p'd ) ; #(s# printf ( "Hn<orr#&t Qass'ord" ) ; } ................................................................................................. ;0. How to obtain the current drive through * ? Ans S# &an $s# t"# f$n&tion R)#tdriv#( ) to o%tain t"# &$rr#nt driv#. !"# R)#tdriv#( ) f$n&tion $s#s 89, f$n&tion 0[1O to )#t t"# &$rr#nt driv# n$m%#r Bin&($d# Cdir#&t."D main( ) { int dis6 ; dis6 = R)#tdriv#( ) + 4A4 . 1 ; printf ( "!"# &$rr#nt driv# is %&Hn", dis6 ) ; } ................................................................................................. ;1. How come the output for both the programs is different when the logic is same? main( ) { int i, M ; for ( i = 1, M = 1 ; i C= ?, M C= 100 ; i++, M++ ) { )oto0+ ( 1, 1, ) ; printf ( "%d %d", i, M ) ; } #isit

http!""www.downloadmela.com"

for more papers

} main( ) { int i, M ; for ( i =1, M = 1; M C= 100, i C= ?; i++, M++ ) { )oto0+ ( 1, 1 ) ; printf ( "%d %d", i, M ) ; } } 9$tp$t .D ? ? Gv#n if (o)i& of %ot" t"# pro)rams is sam# t"# o$tp$t of t"# first pro)ram &om#s o$t to %# 100, 100, %$t of t"# s#&ond pro)ram it is ?, ?. !"# &omma op#rator p(a+s a vita( ro(# insid# t"# for (oop. *t a('a+s &onsid#rs t"# va($# of t"# (at#st varia%(#. ,o, at t"# tim# of t#stin) t"# &ondition in for (oop, t"# va($# of M 'i(( %# &onsid#r#d in t"# firstpro)ram and va($# of i in t"# s#&ond. ................................................................................................. ;/. *an we get the 3 and y coordinate of the current cursor position ? Ans !"# f$n&tion '"#r#0( ) and '"#r#+( ) r#t$rns t"# 0.&oordinat# and +.&oordinat# of t"# &$rr#nt &$rsor position r#sp#&tiv#(+. Eot" t"# f$n&tions r#t$rn an int#)#r va($#. !"# va($# r#t$rn#d %+ '"#r#0( ) is t"# "ori-onta( position of &$rsor and t"# va($# r#t$rn#d %+ '"#r#+( ) is t"# v#rti&a( position of t"# &$rsor. Fo((o'in)pro)ram s"o's "o' to $s# t"# '"#r#0( ) and '"#r#+( ) f$n&tions. Bin&($d# C&onio."D main( ) { printf ( "\$stHn !oHn !#stHn S"#r#Hn t"# &$rsorHn )o#s" ) ; printf ( "<$rr#nt (o&ation is [ %d U %dHn", '"#r#0( ), '"#r#+( ) ) ; } ;3. How do programmatically delete lines in the te3t window? Ans S"i(# 'ritin) pro)rams t"at p#rform s&r##n.%as#d *I9, +o$ ma+ 'ant to.d#(#t# t"# &$rr#nt (in#4s &ont#nts, movin) on# (in# $p, a(( of t"# o$tp$t t"at fo((o's. *n s$&" &as#s a f$n&tion &a((#d d#((in#( ) &an %# $s#d. Fo((o'in) &od# snipp#t i(($strat#s t"# $s# of f$n&tion d#((in#( ). Bin&($d# C&onio."D #isit

http!""www.downloadmela.com"

for more papers

main( ) { int i ; &(rs&r( ) ; for ( i = 0; i C= /3; i++ ) printf ( ":in# %dHrHn", i ) ; printf ( "Qr#ss a 6#+ to &ontin$# " ) ; )#t&"( ) ; )oto0+ ( /, ; ) ; for ( i = ;; i C= 1/; i++ ) d#((in#( ) ; )#t&"( ) ; } ................................................................................................. ;7. How do get the time elapsed between two function calls ? Ans !"# f$n&tion difftim#( ) finds t"# diff#r#n&# %#t'##n t'o tim#s. *t &a(&$(at#s t"# #(aps#d tim# in s#&onds and r#t$rns t"# diff#r#n&# %#t'##n t'o tim#s as a do$%(# va($#. Bin&($d# Ctim#."D Bin&($d# Cstdio."D Bin&($d# Cdos."D main( ) { int a[] = { /, .37, ?;, =>, 11/, 33, .=, 11, 7?, /O, ; } ; int s ; tim#Rt t1, t/ ; II tim#Rt d#fin#s t"# va($# $s#d for tim# f$n&tion s = si-#of ( a ) I / ; t1 = tim# ( 3@:: ) ; s#(Rsort ( a, s ) ; II sort arra+ %+ s#(#&tion sort %$%Rsort ( a, s ) ; II sort arra+ %+ %$%%(# sort m#t"od t/ = tim# ( 3@:: ) ; printf ( "Hn!"# diff#r#n&# %#t'##n t'o f$n&tion &a((s is %f", difftim# ( t/, t1 ) ) ; } *n t"# a%ov# pro)ram '# "av# &a((#d difftim#( ) f$n&tion t"at r#t$rns t"# tim# #(aps#d from t1 #isit

http!""www.downloadmela.com"

for more papers

to t/. ................................................................................................. ;?. How do use swab" # in my program ? Ans !"# f$n&tion s'a%( ) s'aps t"# adMa&#nt %+t#s of m#mor+. *t &opi#s t"# %+t#s from so$r&# strin) to t"# tar)#t strin), provid#d t"at t"# n$m%#r of &"ara&t#rs in t"# so$r&# strin) is #v#n. S"i(# &op+in), it s'aps t"# %+t#s '"i&" ar# t"#n assi)n#d to t"# tar)#t strin). Bin&($d# Cstd(i%."D Bin&($d# Cstdio."D Bin&($d# Cstrin)."D main ( ) { &"ar 1str1 = "", ##s(( snsias( not #" #s as o"#r " ; &"ar 1str/ ; &(rs&r( ) ; s'a% ( str1, str/, str(#n ( str1 ) ) ; printf ( "!"# tar)#t strin) is %sHn", str/ ) ; II o$tp$t .. ,"# s#((s snai(s on t"# s#a s"or# )#t&"( ) ; } ................................................................................................. ;;. !$r%o < provid#s vario$s &ommand (in# &ompi(#r options '"i&" '# &an $s# t"ro$)" !<<. !"# &ompi(#r options in&($d# disp(a+in) sp#&ifi& 'arnin) m#ssa)#s, )#n#ratin) >0>= "ard'ar# instr$&tions, $sin) a fi(#nam# for )#n#ratin) ass#m%(+ &od#, #t&. *nst#ad of &ompi(#r options %#in) #0#&$t#d at &ommand (in# '# &an $s# t"#s# &ompi(#r options in o$rpro)ram . !"is &an %# a&"i#v#d $sin) Bpra)ma options. S# &an $s# vario$s f(a)s 'it" Bpra)ma options to $s# t"# &ompi(#r options. A(( t"#s# f(a)s ar# avai(a%(# in t$r%o <4s on(in# "#(p. ................................................................................................. ;=. * "av# an arra+ d#&(ar#d in fi(# 4F1.<4 as, int a[ ] = { 1, /, 3, 7, ?, ; } ; and $s#d in t"# fi(# 4F/.<4 as, #0t#rn int a[ ] ; n the file -(.*& why si)eof doesn't work on the array a@ A? Ans An #0t#rn arra+ of $nsp#&ifi#d si-# is an in&omp(#t# t+p#. Uo$ &annot app(+ si-#of to it, #isit

http!""www.downloadmela.com"

for more papers

%#&a$s# si-#of op#rat#s d$rin) &ompi(# tim# and it is $na%(# to (#arn t"# si-# of an arra+ t"at is d#fin#d in anot"#r fi(#. Uo$ "av# t"r## 'a+s to r#so(v# t"is pro%(#m 1. *n fi(# 4F1.<4 d#fin# as, int a[ ] = { 1, /, 3, 7, ?, ; } ; int si-#Ra = si-#of ( a ) ; and in fi(# F/.< d#&(ar# as, #0t#rn int a[ ] ; #0t#rn int si-#Ra ; /. *n fi(# 4F1.24 d#fin#, Bd#fin# ATTR,*] ; *n fi(# F1.< d#&(ar# as, Bin&($d# "F1.2" int a[ ATTR,*] ] ; and in fi(# F/.< d#&(ar# as, Bin&($d# "F1.2" #0t#rn int a[ ATTR,*] ] ; 3. *n fi(# 4F1.<4 d#fin# as, int a[ ] = { 1, /, 3, 7, ?, ;, .1 } ; and in fi(# 4F/.<4 d#&(ar# as, #0t#rn int a[ ] ; 2#r# t"# #(#m#nt .1 is $s#d as a s#ntin#( va($#, so t"# &od# &an $nd#rstand t"# #nd 'it"o$t an+ #0p(i&it si-#. ;>. How to delete a line from te3t displayed on the screen? Ans ,om#tim#s, sp#&ia((+ '"#n '# ar# &r#atin) a t#0t #ditor (i6# pro)ram '# ma+ 'is" to a((o' $s#r to d#(#t# a (in#. S# &an do so %+ $sin) t'o f$n&tions nam#(+ &(r#o(( ) and d#((in#( ). !"# &(r#o(( ) f$n&tion d#(#t#s t"# (in# from t"# &$rr#nt &$rsor position to t"# #nd of (in#. !"# d#((in#() f$n&tion d#(#t#s t"# #ntir# (in# at t"# &$rr#nt &$rsor position and mov#s $p t"# fo((o'in) (in#. Fo((o'in) pro)ram s"o's "o' to $s# t"#s# f$n&tions. Bin&($d# C&onio."D main( ) { int i ; for ( i = 1 ; i C= /0 ; i++ ) printf ( "!"is is :in# %dHn", i ) ;

#isit

http!""www.downloadmela.com"

for more papers

)#t&"( ) ; )oto0+ ( 1, = ) ; &(r#o(( ) ; )#t&"( ) ; )oto0+ ( 1, 1/ ) ; d#((in#( ) ; )#t&"( ) ; } ................................................................................................. ;O. How do programmatically insert lines in the te3t window? Ans S# &an ins#rt a %(an6 (in# in t"# t#0t 'indo' $sin) t"# ins(in#( ) f$n&tion. !"is f$n&tion ins#rts (in# at &$rr#nt &$rsor position. S"i(# doin) so, it s"ifts do'n t"# (in#s t"at ar# %#(o' t"# n#'(+ ins#rt#d (in#. Bin&($d# C&onio."D void main( ) { printf ( "!"# (itt(# snai( 'as s(o'(+ movin) $p. ,"# 'ant#dHrHn" ) ; printf ( "to r#a&" t"# top of t"# tr##. *t 'as &"i((+HrHn" ) ; printf ( "'int#r s#ason. Nost of t"# anima(s '#r# r#stin) inHrHn" ) ; printf ( "t"#ir n#sts as t"#r# 'as a "#av+ sno' fa((.HrHn" ) ; printf ( "HrHnQr#ss an+ 6#+ to &ontin$# " ) ; )oto0+ ( 10, / ) ; )#t&"( ) ; ins(in#( ) ; )#t&"( ) ; } ................................................................................................. =0. What will be the output of the following program? main( ) { $nsi)n#d int n$m ; int i ; printf ( "HnGnt#r an+ n$m%#r" ) ; s&anf ( "%$", Jn$m ) ;

#isit

http!""www.downloadmela.com"

for more papers

for ( i = 0 ; i C 1; ; i++ ) printf ( "%d", ( n$m CC i J 1 CC 1? ) W 1 0 ) ; } Ans !"# o$tp$t of t"is pro)ram is t"# %inar+ #K$iva(#nt of t"# )iv#n n$m%#r. S# "av# $s#d %it'is# op#rators to )#t t"# %inar+ n$m%#r. ................................................................................................. =1. Vrap"i&s E$i(din) No$s# <$rsors... *n t#0t mod# t"# mo$s# &$rsor app#ars as a %(o&6, '"#r#as in )rap"i&s mod# it app#ars as an arro'. *f '# 'is" '# &an &"an)# t"# )rap"i&s &$rsor to an+ ot"#r s"ap# t"# 'a+ Sindo's do#s. !"# mo$s# &$rsor in )rap"i&s mod# o&&$pi#s a 1; %+ 1; pi0#( %o0. E+ "i)"(i)"tin) or d#"i)"(i)"tin) som# of t"# pi0#(s in t"is %o0 '# &an )#t t"# d#sir#d s"ap#. For #0amp(#, t"# fo((o'in) %it.patt#rn &an %# $s#d to )#n#rat# t"# &$rsor '"i&" (oo6s (i6# an "o$r.)(ass. 1111111111111111 0000000000000000 1000000000000001 0000000000000000 1111111111111111 0000000000000000 1000000000000001 0000000000000000 0100000000000010 1000000000000001 0010000000000100 1100000000000011 0000100000010000 1111000000001111 0000001001000000 1111110000111111 0000001001000000 1111110000111111 0000100000010000 1111000000001111 0010000000000100 1100000000000011 0100000000000010 1000000000000001 1000000000000001 0000000000000000 1111111111111111 0000000000000000 1000000000000001 0000000000000000 1111111111111111 0000000000000000 No$s# point#r %itmap ,&r##n Nas6 t"# on#4s in t"# mo$s# point#r %itmap indi&at# t"at t"# pi0#( 'o$(d %# dra'n '"#r#as t"# -#ros indi&at# t"at t"# pi0#( 'o$(d stand #ras#d. *t is important to not# t"at t"# mo$s# point#r %it patt#rn is 3/ %+t#s (on). 2o'#v#r, '"i(# a&t$a((+ 'ritin) a pro)ram to &"an)# t"# point#r s"ap# '# n##d a ;7 %+t# %it.map. !"is provision is mad# to #ns$r# t"at '"#n t"# &$rsor r#a&"#s a position on t"# s&r##n '"#r# som#t"in) is a(r#ad+ 'ritt#n or dra'n on(+ t"at portion s"o$(d )#t ov#r'ritt#n '"i&" is to %# o&&$pi#d %+ t"# mo$s# &$rsor. 9f t"# ;7 %+t#s t"# first 3/ %+t#s &ontain a %it mas6 '"i&" is first A38#d 'it" t"# s&r##n ima)#, and t"#n t"# s#&ond 3/ %+t#s %it mas6 is [9T#d 'it" t"# s&r##n ima)#. !"# fo((o'in) pro)ram &"an)#s t"# mo$s# &$rsor in )rap"i&s mod# to r#s#m%(# an "o$r )(ass.

#isit

http!""www.downloadmela.com"

for more papers

B in&($d# ")rap"i&s."" B in&($d# "dos."" $nion TGV, i, o ; str$&t ,TGV, s ; int &$rsor[3/] = { I1 2o$r.)(ass s&r##n mas6 1I 000000, 000000, 000000, 000000, 00>001, 00&003, 00f00f, 00f&3f, 00f&3f, 00f00f, 00&003, 00>001, 000000, 000000, 000000, 000000, I1 !"# mo$s# point#r %itmap 1I 00ffff, 00>001, 00ffff, 00>001, 00700/, 00/007, 00100>, 000/70, 000/70, 000>10, 00/007, 00700/, 00>001, 00ffff, 00>001, 00ffff, }; main( ) { int )d = 8G!G<!, )m ; init)rap" ( J)d, J)m, "& HHt&HH%)i" ) ; if ( initmo$s#( ) == .1 ) { &(os#)rap"( ) ; printf ( "Hn No$s# not insta((#d5" ) ; #0it( ) ; } )oto0+ ( 10, 1 ) ; printf ( "Qr#ss an+ 6#+ to #0it..." ) ; &"an)#&$rsor ( &$rsor ) ; s"o'mo$s#ptr( ) ; )#t&"( ) ; } initmo$s#( ) { i.0.a0 = 0 ; int>; ( 0033, Ji, Jo ) ; r#t$rn ( o.0.a0 == 0 W .1 0 ) ; } s"o'mo$s#ptr( ) { i.0.a0 = 1 ; int>; ( 0033, Ji, Jo ) ; } &"an)#&$rsor ( int 1s"ap# ) { i.0.a0 = O ; I1 s#rvi&# n$m%#r 1I #isit

http!""www.downloadmela.com"

for more papers

i.0.%0 = 0 ; I1 a&t$a( &$rsor position from (#ft 1I i.0.&0 = 0 ; I1 a&t$a( &$rsor position from top 1I i.0.d0 = ( $nsi)n#d ) s"ap# ; I1 offs#t addr#ss of point#r ima)#1I s#)r#ad ( Js ) ; s.#s = s.ds ; I1 s#)m#nt addr#ss of point#r 1I int>;0 ( 0033, Ji, Ji, Js ) ; } =/. !o'#rs 9f 2anoi ,$ppos# t"#r# ar# t"r## p#)s (a%#(#d A, E and <. Fo$r dis6s ar# p(a&#d on p#) A. !"# %ottom.most dis6 is (ar)#st, and dis6s )o on d#&r#asin) in si-# 'it" t"# topmost dis6 %#in) sma((#st. !"# o%M#&tiv# of t"# )am# is to mov# t"# dis6s from p#) A to p#) <, $sin) p#) E as an a$0i(iar+ p#). !"# r$(#s of t"# )am# ar# as fo((o's 9n(+ on# dis6 ma+ %# mov#d at a tim#, and it m$st %# t"# top dis6 on on# of t"# p#)s. A (ar)#r dis6 s"o$(d n#v#r %# p(a&#d on t"# top of a sma((#r dis6. ,$ppos# '# ar# to 'rit# a pro)ram to print o$t t"# s#K$#n&# in '"i&" t"# dis6s s"o$(d %# mov#d s$&" t"at a(( dis6s on p#) A ar# fina((+ transf#rr#d to p#) <. 2#r# it is... main( ) { int n = 7 ; mov# ( n, 4A4, 4E4, 4<4 ) ; } mov# ( n, sp, ap, #p ) int n ; &"ar sp, ap, #p ; { if ( n == 1 ) printf ( "Hn Nov# from %& to %& ", sp, #p ) ; #(s# { mov# ( n . 1, sp, #p, ap ) ; mov# ( 1, sp, 4 4, #p ) ; mov# ( n . 1, ap, sp, #p ) ; } } And "#r# is t"# o$tp$t... Nov# from A to E Nov# from A to < Nov# from E to < Nov# from A to E #isit

http!""www.downloadmela.com"

for more papers

Nov# from < to A Nov# from < to E Nov# from A to E Nov# from A to < Nov# from E to < Nov# from E to A Nov# from < to A Nov# from E to < Nov# from A to E Nov# from A to < Nov# from E to < !"is pro%(#m is t"# famo$s !o'#rs of 2anoi pro%(#m, '"#r#in t"r## p#)s ar# to %# #mp(o+#d for transf#rrin) t"# dis6s 'it" t"# )iv#n &rit#ria. 2#r#4s "o' '# )o a%o$t it. S# "av# t"r## p#)s t"# startin) p#), sp, t"# a$0i(iar+ p#) ap, and t"# #ndin) p#), #p, '"#r# t"# dis6s m$st fina((+ %#. First, $sin) t"# #ndin) p#) as an a$0i(iar+ or s$pportin) p#), '# transf#r a(( %$t t"# (ast dis6 to ap. 3#0t t"# (ast dis6 is mov#d from sp to #p. 3o', $sin) sp as t"# s$pportin) p#), a(( t"# dis6s ar# mov#d from ap to #p. XAY, E and < d#not# t"# t"r## p#)s. !"# r#&$rsiv# f$n&tion mov#( ) is &a((#d 'it" diff#r#nt &om%inations of t"#s# p#)s as startin), a$0i(iar+ and #ndin) p#)s. ................................................................................................. =3. What would be the output of following program? str$&t s+nta0 { int i ; f(oat ) ; &"ar & ; } main( ) { printf ( "* 'on4t )iv# +o$ an+ #rror" ) ; } Ans !"# a%ov# pro)ram 'o$(d )#t &ompi(#d s$&&#ssf$((+ and on #0#&$tion it 'o$(d print t"# m#ssa)# )iv#n in printf(). S"at stri6#s in t"# a%ov# &od# snipp#t is t"# str$&t$r# s+nta0 '"i&" is d#&(ar#d %$t not t#rminat#d 'it" t"# stat#m#nt t#rminator, t"# s#mi&o(on. !"# &ompi(#r 'o$(d not )iv# an+ #rror m#ssa)# for it, as it ass$m#s t"at main( ) f$n&tion "av# a r#t$rn t+p# of str$&t s+nta0 and "#n&# 'o$(d s$&&#ssf$((+ &ompi(# and #0#&$t# t"# pro)ram. ................................................................................................. =7. How to get the memory si)e ? #isit

http!""www.downloadmela.com"

for more papers

Ans <onsid#r t"# fo((o'in) pro)ram Bin&($d# Cstdio."D Bin&($d# C%ios."D main( ) { int m#msi-#; m#msi-# = %iosm#mor+( ) ; printf ( "TAN si-# = %dLHn",m#msi-# ) ; r#t$rn 0 ; } !"# f$n&tion %iosm#mor+ $s#s E*9, int#rr$pt 001/ to r#t$rn t"# si-# of m#mor+. ................................................................................................. =?. -loat -ormat How does * compiler stores float values ? Ans *n <, t"# f(oat va($#s ar# stor#d in a mantissa and #0pon#nt form. S"i(# 'ritin) a n$m%#r '# sp#&if+ t"# #0pon#nt part in t"# form of %as# 10. E$t, in &as# of < &ompi(#r, t"# #0pon#nt for f(oats is stor#d in t"# form of %as# /. 9%vio$s(+, %#&a$s#, &omp$t#r stor#s t"# n$m%#rs in %inar+ form. !"# < &ompi(#r fo((o's an *GGG standard to stor# a f(oat. !"# *GGG format #0pr#ss#s a f(oatin).point n$m%#r in a %inar+ form 6no'n as ^norma(i-#d4 form. 3orma(i-ation invo(v#s adM$stin) t"# #0pon#nt so t"at t"# "%inar+ point" (t"# %inar+ ana(o) of t"# d#&ima( point) in t"# mantissa a('a+s (i#s to t"# ri)"t of most si)nifi&ant non-#ro di)it. *n %inar+ r#pr#s#ntation, t"is m#ans t"at t"# most si)nifi&ant di)it of t"# mantissa is a('a+s a 1. !"is prop#rt+ of t"# norma(i-#d r#pr#s#ntation is #0p(oit#d %+ t"# *GGG format '"#n storin) t"# mantissa. :#t $s &onsid#r an #0amp(# of )#n#ratin) t"# norma(i-#d form of a f(oatin) point n$m%#r. ,$ppos# '# 'ant to r#pr#s#nt t"# d#&ima( n$m%#r ?.3=?. *ts %inar+ #K$iva(#nt &an %# o%tain#d as s"o'n %#(o' /P? .3=? 0 / = 0.=?0 0 P...... .=?0 0 / = 1.?00 1 /P/1 .?00 0 / = 1.000 1 P...... /P10 P...... P01 Sritin) r#maind#rs in r#v#rs# 'ritin) '"o(# parts in t"# sam# ord#r '# )#t 101 ord#r in '"i&" t"#+ ar# o%tain#d '# )#t 011 t"$s t"# %inar+ #K$iva(#nt of ?.3=? 'o$(d %# 101.011. !"# norma(i-#d form of t"is %inar+ n$m%#r is o%tain#d %+ adM$stin) t"# #0pon#nt $nti( t"# d#&ima( point is to t"# ri)"t of most si)nifi&ant 1. *n t"is &as# t"# r#s$(t is 1.01011 0 //. !"# *GGG #isit

http!""www.downloadmela.com"

for more papers

format for f(oatin) point stora)# $s#s a si)n %it, a mantissa and an #0pon#nt for r#pr#s#ntin) t"# po'#r of /. !"# si)n %it d#not#s t"# si)n of t"# n$m%#r a 0 r#pr#s#nts a positiv# va($# and a 1 d#not#s a n#)ativ# va($#. !"# mantissa is r#pr#s#nt#d in %inar+. <onv#rtin) t"# f(oatin).point n$m%#r to its norma(i-#d form r#s$(ts in a mantissa '"os# most si)nifi&ant di)it is a('a+s 1. !"# *GGG format ta6#s advanta)# of t"is %+ not storin) t"is %it at a((. !"# #0pon#nt is an int#)#r stor#d in $nsi)n#d %inar+ format aft#r addin) a positiv# int#)#r %ias. !"is #ns$r#s t"at t"# stor#d #0pon#nt is a('a+s positiv#. !"# va($# of t"# %ias is 1/= for f(oats and 10/3 for do$%(#s. !"$s, 1.01011 0 // is r#pr#s#nt#d as s"o'n %#(o' ... ............... .............................................. P 0 P 100 0000 1 P 010 1100 0000 0000 0000 0000 P ... ................ ............................................. si)n %it #0pon#nt. mantissa stor#d in norma(i-#d form o%tain#d aft#r addin) a %ias 1/= to #0pon#nt / 5ata !tructures Which is the best sorting method? Ans !"#r# is no sortin) m#t"od t"at is $niv#rsa((+ s$p#rior to a(( ot"#rs. !"# pro)ramm#r m$st &ar#f$((+ #0amin# t"# pro%(#m and t"# d#sir#d r#s$(ts %#for# d#&idin) t"# parti&$(ar sortin) m#t"od. ,om# of t"# sortin) m#t"ods ar# )iv#n %#(o' E$%%(# sort S"#n a fi(# &ontainin) r#&ords is to %# sort#d t"#n E$%%(# sort is t"# %#st sortin) m#t"od '"#n sortin) %+ addr#ss is $s#d. Esort *t &an %# r#&omm#nd#d if t"# inp$t to t"# fi(# is 6no'n to %# n#ar(+ sort#d. N#ansort *t &an %# r#&omm#nd#d on(+ for inp$t 6no'n to %# v#r+ n#ar(+ sort#d. _$i&6 ,ort *n t"# virt$a( m#mor+ #nvironm#nt, '"#r# pa)#s of data ar# &onstant(+ %#in) s'app#d %a&6 and fort" %#t'##n #0t#rna( and int#rna( stora)#. *n pra&ti&a( sit$ations, K$i&6 sort is oft#n t"# fast#st avai(a%(# %#&a$s# of its (o' ov#r"#ad and its av#ra)# %#"avior. 2#ap sort V#n#ra((+ $s#d for sortin) of &omp(#t# %inar+ tr##. ,imp(# ins#rtion sort and strai)"t s#(#&tion sort Eot" ar# mor# #ffi&i#nt t"an %$%%(# sort. ,#(#&tion sort is r#&omm#nd#d for sma(( fi(#s '"#n r#&ords ar# (ar)# and for r#v#rs# sit$ation ins#rtion sort is r#&omm#nd#d. !"# "#ap sort and K$i&6 sort ar# %ot" mor# #ffi&i#nt t"an ins#rtion or s#(#&tion for (ar)# n$m%#r of data. ,"#(( sort *t is r#&omm#nd#d for mod#rat#(+ si-#d fi(#s of s#v#ra( "$ndr#d #(#m#nts. Tadi0 sort *t is r#asona%(+ #ffi&i#nt if t"# n$m%#r of di)its in t"# 6#+s is not too (ar)#. =;. *alculating Wasted Bytes 1n 5isk

#isit

http!""www.downloadmela.com"

for more papers

S"#n a fi(# )#ts stor#d on t"# dis6, at a tim# 89, a((o&at#s on# &($st#r for it. A &($st#r is not"in) %$t a )ro$p of s#&tors. 2o'#v#r, sin&# a(( fi(# si-#s &annot %# #0p#&t#d to %# a m$(tip(# of ?1/ %+t#s, '"#n a fi(# )#ts stor#d oft#n part of t"# &($st#r r#mains $no&&$pi#d. !"is spa&# )o#s 'ast# $n(#ss t"# fi(# si-# )ro's to o&&$p+ t"#s# 'ast#d %+t#s. !"# fo((o'in) pro)ram finds o$t "o' m$&" spa&# is 'ast#d for a(( fi(#s in a(( t"# dir#&tori#s of t"# &$rr#nt driv#. Bin&($d# Cdir."D Bin&($d# Cdos."D Bin&($d# Cstdio."D Bin&($d# Cstrin)."D Bin&($d# Cstd(i%."D $nsi)n#d %+t#sRp#rR&($st#r ; $nsi)n#d (on) 'ast#dR%+t#s ; $nsi)n#d (on) n$mRfi(#s = 0 ; main( ) { int ptr = 0, f(a) = 0, first = 0 ; str$&t ff%(6 f[?0] ; str$&t dfr## fr## ; I1 )#t &($st#r information and &a(&$(at# %+t#s p#r &($st#r 1I )#tdfr## ( 0, Jfr## ) ; %+t#sRp#rR&($st#r = fr##.dfR%s#& 1 fr##.dfRs&($s ; &"dir ( "HH" ) ; I1 &"#&6 o$t fi(#s in root dir#&tor+ first 1I &a(R'ast#( ) ; I1 (oop $nti( a(( dir#&tori#s s&ann#d 1I '"i(# ( ptr 5= .1 ) { I1 s"o$(d * do a findfirst or a findn#0tW 1I if ( first == 0 ) f(a) = findfirst ( "1.1", Jf[ptr], FAR8*TG< ) ; #(s# f(a) = findn#0t ( Jf[ptr] ) ; '"i(# ( f(a) == 0 ) { I1 ma6# s$r# its a dir#&tor+ and s6ip ov#r . J .. #ntri#s 1I if ( f[ptr].ffRattri% == FAR8*TG< JJ f[ptr].ffRnam#[0] 5= 4.4 ) { f(a) = &"dir ( f[ptr].ffRnam# ) ; I1 tr+ &"an)in) dir#&tori#s 1I if ( f(a) == 0 ) I1 did &"an)# dir 'or6W 1I { &a(R'ast#( ) ; first = 0 ; I1 s#t for findfirst on n#0t pass 1I %r#a6 ; } #isit

http!""www.downloadmela.com"

for more papers

} f(a) = findn#0t ( Jf[ptr] ) ; I1 s#ar&" for mor# dirs 1I } if ( f(a) 5= 0 PP ptr == 7O ) I1 didn4t find an+ mor# dirs 1I { ptr.. ; &"dir ( ".." ) ; I1 )o %a&6 on# (#v#( 1I first = 1 ; I1 s#t to findn#0t on n#0t pass 1I } #(s# ptr++ ; } printf ( "!"#r# ar# %($ %+t#s 'ast#d in %($ fi(#s.Hn", 'ast#dR%+t#s, n$mRfi(#s ) ; } &a(R'ast#( ) { int f(a) = 0 ; (on) f$((R&($st#r ; str$&t ff%(6 ff ; I1 (oo6 for a(( fi(# t+p#s 1I f(a) = findfirst ( "1.1", Jff, FART893:U P FAR2*88G3 P FAR,U,!GN P FARAT<2 ); '"i(# ( f(a) == 0 ) { n$mRfi(#s++ ; f$((R&($st#r = ff.ffRfsi-# I %+t#sRp#rR&($st#r 1 %+t#sRp#rR&($st#r ; 'ast#dR%+t#s += %+t#sRp#rR&($st#r . ( ff.ffRfsi-# . f$((R&($st#r ) ; f(a) = findn#0t ( Jff ) ; } } 5ata !tructures .olish Cotation !"# m#t"od of 'ritin) a(( op#rators #it"#r %#for# t"#ir op#ration, or aft#r t"#m, is &a((#d Qo(is" notation, in "onor of its dis&ov#r#r, t"# Qo(is" mat"#mati&ian \an :$6asi#'i&-. S"#n t"# op#rators ar# 'ritt#n %#for# t"#ir op#rands, it is &a((#d t"# pr#fi0 form. S"#n t"# op#rators &om# aft#r t"#ir op#rands. *t is &a((#d t"# postfi0 form, or, som#tim#s r#v#rs# Qo(is" form or s$ffi0 form. *n t"is &ont#0t, it is &$stomar+ to $s# t"# &oin#d p"ras# infi0 form to d#not# t"# $s$a( &$stom of 'ritin) %inar+ op#rators %#t'##n t"#ir op#rands. For #0amp(#, t"# #0pr#ssion A + E %#&om#s +AE in pr#fi0 form and AE+ in postfi0 form. *n t"# #0pr#ssion A + E 0 <, t"# m$(tip(i&ation is don# first, so '# &onv#rt it first, o%tainin) first A + ( E<0 ) and t"#n AE<0+ in postfi0 form. !"# pr#fi0 form of t"is #0pr#ssion is +A 0 E<. !"# pr#fi0 and postfi0 forms ar# not r#(at#d %+ ta6in) mirror ima)#s or ot"#r s$&" simp(# transformation. A(so a(( #isit

http!""www.downloadmela.com"

for more papers

par#nt"#s#s "av# %##n omitt#d in t"# Qo(is" forms. ................................................................................................. ==. The Dongjmp $nd !etjmp !"# < pro)rammin) (an)$a)# do#s not (#t +o$ n#st f$n&tions. Uo$ &annot 'rit# a f$n&tion d#finition insid# anot"#r f$n&tion d#finition, as in int f$n1( ) { int f$n/() I1 s$&" n#stin) of f$n&tions is not a((o'#d 1I { ..... } } E#&a$s# of t"is r#stri&tion it is not possi%(# to "id# f$n&tion nam#s insid# a "i#rar&"+. As a r#s$(t a(( t"# f$n&tions t"at +o$ d#&(ar# 'it"in a pro)ram ar# visi%(# to #a&" ot"#r. !"is of &o$rs# is not a maMor dra'%a&6 sin&# on# &an (imit visi%i(it+ %+ )ro$pin) f$n&tions 'it"in s#parat# < so$r&# fi(#s t"at %#(on) to diff#r#nt (o)i&a( $nits of t"# pro)ram. < do#s, "o'#v#r, s$ff#r in anot"#r 'a+ %#&a$s# of t"is d#si)n d#&ision. *t provid#s no #as+ 'a+ to transf#r &ontro( o$t of a f$n&tion #0&#pt %+ r#t$rnin) to t"# #0pr#ssion t"at &a((#d t"# f$n&tion. For t"# vast maMorit+ of f$n&tion &a((s, t"at is a d#sira%(# (imitation. Uo$ 'ant t"# dis&ip(in# of n#st#d f$n&tion &a((s and r#t$rns to "#(p +o$ $nd#rstand f(o' of &ontro( t"ro$)" a pro)ram. 3#v#rt"#(#ss, on som# o&&asions t"at dis&ip(in# is too r#stri&tiv#. !"# pro)ram is som#tim#s #asi#r to 'rit#, and to $nd#rstand, if +o$ &an M$mp o$t of on# or mor# f$n&tion invo&ations at a sin)(# stro6#. Uo$ 'ant to %+pass t"# norma( f$n&tion r#t$rns and transf#r &ontro( to som#'"#r# in an #ar(i#r f$n&tion invo&ation. For #0amp(#, +o$ ma+ 'ant to r#t$rn to #0#&$t# som# &od# for #rror r#&ov#r+ no matt#r '"#r# an #rror is d#t#&t#d in +o$r app(i&ation. !"# s#tMmp and t"# (on)Mmp f$n&tions provid# t"# too(s to a&&omp(is" t"is. !"# s#tMmp f$n&tion sav#s t"# "stat#" or t"# "&ont#0t" of t"# pro&#ss and t"# (on)Mmp $s#s t"# sav#d &ont#0t to r#v#rt to a pr#vio$s point in t"# pro)ram. S"at is t"# &ont#0t of t"# pro&#ssW *n )#n#ra(, t"# &ont#0t of a pro&#ss r#f#rs to information t"at #na%(#s +o$ to r#&onstr$&t #0a&t(+ t"# 'a+ t"# pro&#ss is at a parti&$(ar point in its f(o' of #0#&$tion. *n < pro)ram t"# r#(#vant information in&($d#s K$antiti#s s$&" as va($#s of ,Q, ,,, F:AV,, <,, *Q, EQ, 8*, G,, ,* and 8, r#)ist#rs. !o sav# t"is information !$r%o < $s#s t"# fo((o'in) str$&t$r#, '"i&" is d#fin#d, in t"# "#ad#r fi(# 4s#tMmp."4. t+p#d#f str$&t { $nsi)n#d MRsp ; $nsi)n#d MRss ; $nsi)n#d MRf(a) ; $nsi)n#d MR&s ; #isit

http!""www.downloadmela.com"

for more papers

$nsi)n#d MRip ; $nsi)n#d MR%p ; $nsi)n#d MRdi ; $nsi)n#d MR#s ; $nsi)n#d MRsi ; $nsi)n#d MRds ; } MmpR%$f[1] ; !"is is a s+st#m.d#p#nd#nt data t+p# %#&a$s# diff#r#nt s+st#ms mi)"t r#K$ir# diff#r#nt amo$nts of information to &apt$r# t"# &ont#0t of a pro&#ss. *n !$r%o <, MmpR%$f is simp(+ an arra+ of t#n /.%+t# int#)#rs. !o $nd#rstand t"# m#&"ani&s of s#tMmp and (on)Mmp, (oo6 at t"# fo((o'in) &od# fra)m#nt. Bin&($d# "s#tMmp."" MmpR%$f %$f ; main( ) { if ( s#tMmp ( %$f ) == 0 ) pro&#ss( ) ; #(s# "and(#R#rror( ) ; I1 #0#&$t#d '"#n (on)Mmp is &a((#d 1I } pro&#ss( ) { int f(a) = 0 ; I1 som# pro&#ssin) is don# "#r# 1I I1 if an #rror o&&$rs d$rin) pro&#ssin) f(a) is s#t $p 1I if ( f(a) ) (on)Mmp ( %$f, 1 ) ; } @pon #ntr+ to s#tMmp t"# sta&6 &ontains t"# addr#ss of t"# %$ff#r %$f and t"# addr#ss of t"# if stat#m#nt in t"# main f$n&tion, to '"i&" s#tMmp 'i(( r#t$rn. !"# s#tMmp f$n&tion &opi#s t"is r#t$rn addr#ss as '#(( as t"# &$rr#nt va($#s of r#)ist#rs, ,Q, ,,, F:AV,, EQ, 8*, G,, ,* and 8,, into t"# %$ff#r %$f. !"#n s#tMmp r#t$rns 'it" a -#ro. *n t"is &as#, t"# if stat#m#nt is satisfi#d and t"# pro&#ss( ) f$n&tion is &a((#d. *f som#t"in) )o#s 'ron) in pro&#ss( ) (indi&at#d %+ t"# f(a) varia%(#), '# &a(( (on)Mmp 'it" t'o ar)$m#nts t"# first is t"# %$ff#r t"at &ontains t"# &ont#0t to '"i&" '# 'i(( r#t$rn. S"#n t"# sta&6 r#v#rts %a&6 to t"is sav#d stat#, and t"# r#t$rn stat#m#nt in (on)Mmp is #0#&$t#d, it 'i(( %# as if '# '#r# r#t$rnin) from t"# &a(( to s#tMmp, '"i&" ori)ina((+ sav#d t"# %$ff#r %$f. !"# s#&ond ar)$m#nt to (on)Mmp sp#&ifi#s t"# r#t$rn va($# to %# $s#d d$rin) t"is r#t$rn. *t s"o$(d %# ot"#r t"an -#ro so t"at in t"# if stat#m#nt '# &an t#(( '"#t"#r t"# r#t$rn is ind$&#d %+ a (on)Mmp. !"# s#tMmpI(on)Mmp &om%ination #na%(#s +o$ to M$mp $n&onditiona((+ from on# < f$n&tion to anot"#r 'it"o$t $sin) t"# &onv#ntiona( r#t$rn stat#m#nts. Gss#ntia((+, s#tMmp mar6s t"# d#stination of t"# M$mp and (on)Mmp is a non.(o&a( )oto t"at #0#&$t#s t"# M$mp. 8ata ,tr$&t$r#s #isit

http!""www.downloadmela.com"

for more papers

<omparison !r##s... !"# &omparison tr##s a(so &a((#d d#&ision tr## or s#ar&" tr## of an a()orit"m, is o%tain#d %+ tra&in) t"ro$)" t"# a&tions of t"# a()orit"m, r#pr#s#ntin) #a&" &omparison of 6#+s %+ a v#rt#0 of t"# tr## ('"i&" '# dra' as a &ir&(#). *nsid# t"# &ir&(# '# p$t t"# ind#0 of t"# 6#+ a)ainst '"i&" '# ar# &omparin) t"# tar)#t 6#+. Eran&"#s ((in#s) dra'n do'n from t"# &ir&(# r#pr#s#nt t"# possi%(# o$t&om#s of t"# &omparison and ar# (a%#(#d a&&ordin)(+. S"#n t"# a()orit"m t#rminat#s, '# p$t #it"#r F (for fai($r#) or t"# (o&ation '"#r# t"# tar)#t is fo$nd at t"# #nd of t"# appropriat# %ran&", '"i&" '# &a(( a (#af, and dra' as a sK$ar#. :#av#s ar# a(so som#tim#s &a((#d #nd v#rti&#s or #0t#rna( v#rti&#s of t"# tr##. !"# r#mainin) v#rti&#s ar# &a((#d t"# int#rna( v#rti&#s of t"# tr##. !"# &omparison tr## for s#K$#ntia( s#ar&" is #sp#&ia((+ simp(#. ................................................................................................. =>. !uppose we have a floating%point number with higher precision say '(.'(97:;9:; and we wish it to be printed with only precision up to two decimal places. How can do this? Ans. !"is &an a&"i#v#d t"ro$)" t"# $s# of s$ppr#ssion &"ar 414 in t"# format strin) of printf( ) '"i&" is s"o'n in t"# fo((o'in) pro)ram. main( ) { int p = / ; f(oat n = 1/.1/;7>=;>= ; printf ( "%.1f",p, n ) ; } ................................................................................................. =O. !pawning A(( pro)rams t"at '# #0#&$t# from 89, prompt &an %# t"o$)"t of as &"i(dr#n of <9NNA38.<9N. !"$s, t"# pro)ram t"at '# #0#&$t# is a &"i(d pro&#ss, '"#r#as <9NNA38.<9N r$nnin) in m#mor+ is its par#nt. !"# pro&#ss of a par#nt pro&#ss )ivin) %irt" to a &"i(d pro&#ss is 6no'n as 4spa'nin)4. *f t"# spa'n#d pro)ram so d#sir#s, it ma+ in t$rn spa'n &"i(dr#n of its o'n, '"i&" t"#n #0#&$t# and r#t$rn &ontro( to t"#ir par#nt. S"o is t"# par#nt of <9NNA38.<9NW <9NNA38.<9N its#(f. S# &an tra&# t"# an&#stors of o$r pro)ram $sin) t"# fi#(d Qar#nt Qro&#ss *8 (Q*8) pr#s#nt at offs#t 001; in t"# Qro)ram ,#)m#nt Qr#fi0 (Q,Q). !o tra&# t"is an&#str+ o$r pro)ram s"o$(d first (o&at# its Q,Q, #0tra&t t"# par#nt pro&#ss *8 from it and t"#n $s# t"is to find Q,Q of t"# par#nt. !"is pro&#ss &an %# r#p#at#d ti(( '# r#a&" <9NNA38.<9N (pro&#ss *8 of <9NNA38.<9N is its o'n Q,Q), t"# fat"#r of a(( pro&#ss#s. 2#r# is a pro)ram '"i&" a&"i#v#s t"is... I1 ,QAS3.< 1I Bin&($d# "dos."" #isit

http!""www.downloadmela.com"

for more papers

$nsi)n#d o(dpsp, n#'psp, far 1#%Rs#), i ; &"ar far 1#%Rptr ; main( ) { o(dpsp = Rpsp ; '"i(# ( 1 ) { printf ( "Hn" ) ; printnam# ( o(dpsp ) ; printf ( " spa'n#d %+ " ) ; n#'psp = 1 ( ( $nsi)n#d far 1 ) NLRFQ ( o(dpsp, 001; ) ) ; if ( 1 ( ( $nsi)n#d 1 ) NLRFQ ( n#'psp, 001; ) ) == n#'psp ) %r#a6 ; #(s# o(dpsp = n#'psp ; printnam# ( n#'psp ) ; } printf ( "%./0s (%07[)", "<9NNA38.<9N", n#'psp ) ; } printnam# ( $nsi)n#d (psp ) { &"ar driv#[?], dir[;>], nam#[13], #0t[?] ; #%Rs#) = ( $nsi)n#d far 1 ) NLRFQ ( (psp, 00/< ) ; #%Rptr = NLRFQ ( 1#%Rs#), 0 ) ; i=0; '"i(# ( 1 ) { if ( #%Rptr[i] == 0 ) { if ( #%Rptr[i + 1] == 0 JJ #%Rptr[i + /] == 1 ) { i += 7 ; %r#a6 ; } } i++ ; #isit

http!""www.downloadmela.com"

for more papers

} fnsp(it ( #%Rptr + i, driv#, dir, nam#, #0t ) ; str&at ( nam#, #0t ) ; printf ( "%./0s (%07[)", nam#, o(dpsp ) ; } 9n r$nnin) t"# pro)ram from 'it"in !< t"# o$tp$t o%tain#d is s"o'n %#(o'. ,QSA3.G[G (?>AO) spa'n#d %+ !<.G[G (0;=/) !<.G[G (0;=/) spa'n#d %+ <9NNA38.<9N (0?E>). !"# pro)ram simp(+ &opi#s its o'n pro&#ss *8 in t"# varia%(# o(dpsp and t"#n $s#s it to #0tra&t its o'n fi(#nam# from its #nvironm#nt %(o&6. !"is is don# %+ t"# f$n&tion printnam#( ). !"# va($# in o(dpsp is t"#n $s#d to r#tri#v# t"# par#nt4s Q*8 in n#'psp. From t"#r# t"# pro)ram (oops r#portin) t"# va($#s of o(dpsp, n#'psp and t"# &orr#spondin) fi(# nam#s $nti( t"# pro)ram r#a&"#s <9NNA38.<9N. !"# printnam#( ) f$n&tion first (o&at#s t"# #nvironm#nt %(o&6 of t"# pro)ram and t"#n #0tra&ts t"# fi(# nam# from t"# #nvironm#nt %(o&6. !"# fnsp(it( ) f$n&tion "as %##n $s#d to #(iminat# t"# pat" pr#s#nt prior to t"# fi(# nam#. 8o not r$n t"# pro)ram from &ommand (in# sin&# it 'o$(d )iv# +o$ on(+ on# (#v#( of an&#str+. 8ata ,tr$&t$r#s <"oosin) t"# data str$&t$r#s to %# $s#d for information r#tri#va(. For pro%(#ms of information r#tri#va(, &onsid#r t"# si-#, n$m%#r, and (o&ation of t"# r#&ords a(on) 'it" t"# t+p# and str$&t$r# of t"# 6#+s '"i(# &"oosin) t"# data str$&t$r#s to %# $s#d. For sma(( r#&ords, "i)". sp##d int#rna( m#mor+ 'i(( %# $s#d, and %inar+ s#ar&" tr##s 'i(( (i6#(+ prov# ad#K$at#. For information r#tri#va( from dis6 fi(#s, m#t"ods #mp(o+in) m$(ti'a+ %ran&"in), s$&" as tr##s, E. tr##s , and "as" ta%(#s, 'i(( $s$a((+ %# s$p#rior. !ri#s ar# parti&$(ar(+ s$it#d to app(i&ations '"#r# t"# 6#+s ar# str$&t$r#d as a s#K$#n&# of s+m%o(s and '"#r# t"# s#t of 6#+s is r#(ativ#(+ d#ns# in t"# s#t of a(( possi%(# 6#+s. For ot"#r app(i&ations, m#t"ods t"at tr#at t"# 6#+ as a sin)(# $nit 'i(( oft#n prov# s$p#rior. E.tr##s, to)#t"#r 'it" vario$s )#n#ra(i-ation and #0t#nsions, &an %# $s#f$((+ app(i#d to man+ pro%(#ms &on&#rn#d 'it" #0t#rna( information r#tri#va(.

$%. Variably Dimensioned Arrays &hile dealing with 'cientific or (ngineering problems one is often re)uired to make use of multi* dimensioned array. +owever, when it comes to passing multidimensional arrays to a function , is found wanting. This is because the , compiler wants to know the size of all but the first dimension of any array passed to a function. -or instance, we can define a function compute . int n, float /01 2, but not compute . int n, /01012.

#isit

http!""www.downloadmela.com"

for more papers

Thus, , can deal with variably dimensioned 1*D arrays, but when an array has more than one dimension, the , compiler has to know the size of the last dimensions e/pressed as a constant. This problem has long been recognized, and some of the solutions that are often used are! Declare the arrays in the functions to be big enough to tackle all possible situations. This can lead to a wastage of lot of precious memory in most cases. 3nother solution is to construct multiple*dimension array as an array of pointers. -or e/ample, a matri/ .2*D array2 of floats can be declared as a 1*D array of float pointers, with each element pointing to an array of floats. The problem with this method is that the calling function has to define all arrays in this fashion. This means that any other computations done on the arrays must take this special structure into account. 3nother easy solution, though seldom used, e/ists. This is based on the following method! ass the array to the function as though it is a pointer to an array of floats .or the appropriate data type2, no matter how many dimensions the array actually has, along with the dimensions of the array. 4eference individual array elements as offsets from this pointer. &rite your algorithm so that array elements are accessed in storage order. The following program for multiplying two matrices illustrates this procedure. 5 define 6 7 5 define 8 2 5 define 9 float a061081, b0810 1, c0610 1 : void mulmat . int, int, int, float;, float;, float; 2 : main. 2 < int i, = : for . i > % : i ? 6 : i@@ 2 for . = > % : = ? 8 : =@@ 2 a0i10=1 > i @ = : for . i > % : i ? 8 : i@@ 2 for . = > % : = ? : =@@ 2 b0i10=1 > i @ = : mulmat . 6, 8, , a, b, c 2 : for . i > % : i ? 6 : i@@ 2 < printf . ABnA 2 : for . = > % : = ? : =@@ 2 printf . ACfBtA, c0i10=1 2 : D D

#isit

http!""www.downloadmela.com"

for more papers

void mulmat . int m, int n, int p, float ;a, float ;b, float ;c 2 < float ;ptrtob, ;ptrtoc : int i, =, k, nc : "; set all elements of matri/ c to % ;" for . i > % : i ? m ; p : i@@ 2 ;. c @ i 2 > % : for . i > % : i ? m : i@@ 2 < ptrtob > b : for . k > % : k ? n : k@@ 2 < ptrtoc > c : for . = > % : = ? p : =@@ 2 ;ptrtoc@@ @> ;a ; ;ptrtob@@ : a@@ : D c @> p : D D &e know that , stores array elements in a row*ma=or order. +ence to ensure that the elements are accessed in the storage order the above program uses a variation of the normal matri/*multiplication procedure. The pseudo code for this is given below! for i > 1 to m for = > 1 to p c0i10=1 > % end for k > 1 to n for = > 1 to p c0i10=1 > c0i10=1 @ a0i10k1 ; b0k10=1 end end end ************************************************************************************************* $1. Why is it not possible to scan strings from keyboard in case of array of pointers to string? 3ns! &hen an array is declared, dimension of array should be specified so that compiler can allocate memory for the array. &hen array of pointers to strings is declared its elements would contain garbage addresses. These addresses would be passed to scanf. 2. 'o strings can be received but they would get stored at unkown locations. This is unsafe. #isit

http!""www.downloadmela.com"

for more papers

************************************************************************************************* $2. Bit Arrays If in a program a variable is to take only two values 1 and %, we really need only a single bit to store it. 'imilarly, if a variable is to take values from % to 7, then two bits are sufficient to store these values. 3nd if a variable is to take values from % through E, then three bits will be enough, and so on. &hy waste an entire integer when one or two or three bits will doF Gecause there arenHt any one bit or two bit or three bit data types available in ,. +owever, when there are several variables whose ma/imum values are small enough to pack into a singlememory location, we can use Ibit fieldsH to store several values in a single integer. Git fields are discussed in most standard , te/ts. They are usually used when we want to store assorted information which can be accommodated in 1, 2, 7 bits etc. -or e/ample, the following data about an employee can be easily stored using bit fields. male or female single, married, divorced or widowed have one of the eight different hobbies can choose from any of the fifteen different schemes proposed by the company to pursue his"her hobby. This means we need one bit to store gender, two to store marital status, three for hobby, and four for scheme .with one value used for those who are not desirous of availing any of the schemes2. &e need ten bits altogether, which means we can pack all this information into a single integer, since an integer is 1J bits long. 3t times we may need to store several True or -alse statuses. In such cases instead of using bit fields using an array of bits would be more sensible. Kn this array we may be re)uired to perform the following operations! 'et a bit .make it 12. ,lear a bit .make it %2. Test the status of a bit in the array. 4each the appropriate bit slot in the array. Lenerate a bit mask for setting and clearing a bit. &e can implement these operations using macros given below! 5define ,+34'IM( $ 5define 63'N . y 2 . 1 ?? y C ,+34'IM( 2 5define GIT'OKT . y 2 . y " ,+34'IM( 2 5define '(T . /, y 2 . /0GIT'OKT. y 21 P> 63'N. y 2 2 5define ,O(34 . /, y 2 . /0GIT'OKT. y 21 Q> R63'N. y 2 2 5define T('T . /, y 2 . /0GIT'OKT. y 21 Q 63'N. y 2 2 5define 8S6'OKT' . n 2 . . n @ ,+34'IM( * 12 " ,+34'IM( 2 Ssing these macros we can declare an array of T% bits be saying,

#isit

http!""www.downloadmela.com"

for more papers

char arr08S6'OKT'.T%21 : To set the 2%th bit we can say, '(T.arr, 2% 2 : 3nd if we are to test the status of 9%th bit we may say, if . T('T . arr, 9% 2 2 Ssing bit arrays often results into saving a lot of precious memory. -or e/ample, the following program which implements the 'ieve of (ratosthenes for generating prime numbers smaller than 1%% re)uires only 17 bytes. +ad we implemented the same logic using anarray of integers we would have re)uired an array of 1%% integers, that is 2%% bytes. 5include ?stdio.hU 5include ?string.hU 5define 63V 1%% main. 2 < char arr08S6'OKT'. 63V 21 : int i, = : memset . arr, %, 8S6'OKT'. 63V 2 2 : for . i > 2 : i ? 63V : i@@ 2 < if . WT('T . arr, i 2 2 < printf . ABnCdA, i 2 : for . = > i @ i : = ? 63V : = @> i 2 '(T . arr, = 2 : D D D ************************************************************************************************* $7. Information Hiding in C Though , language doesnHt fully support encapsulation as ,@@ does, there is a simple techni)ue through which we can implement encapsulation in ,. The techni)ue that achieves this is modular programming in ,. 6odular programming re)uires a little e/tra work from the programmer, but pays for itself during maintenance. To understand this techni)ue let us take the e/ample of the popular stack data structure. There are many methods of implementing a stack .array, linked list, etc.2. Information hiding teaches that users should be able to push and pop the stackHs elements without knowing about the stackHs implementation. 3 benefit of this sort of information hiding is that users donHt have to change their code even if the implementation details change. ,onsider the following scenario!

#isit

http!""www.downloadmela.com"

for more papers

To be able to appreciate the benefits of modular programming and thereby information hiding, would first show a traditional implementation of the stack data structure using pointers and a linked list of structures. The main. 2function calls the push. 2 and pop. 2 functions. 5include ?alloc.hU typedef int element : void initializeXstack . struct node ;; 2 : void push . struct node ;;, element 2 : element pop . struct node ; 2 : int isempty . struct node ; 2 : struct node < element data : struct node ;ne/t : D: void main. 2 < struct node ;top : element num : initializeXstack . Qtop 2 : push . Qtop, 1% 2 : push . Qtop, 2% 2 : push . Qtop, 7% 2 : if . isempty . top 2 2 printf . ABn'tack is emptyA 2 : else < num > pop . top 2 : printf . ABn opped CdA, num 2 : D D void initializeXstack . struct node ;;p 2 < ;p > 8SOO : D void push . struct node ;;p, element n 2 < struct node ;r : r > . struct node ;2 malloc . sizeof . struct node 2 2 : r *U data > n : if . ;p >> 8SOO 2 r *U ne/t > 8SOO : else r *U ne/t > ;p : ;p > r : D #isit

http!""www.downloadmela.com"

for more papers

element pop . struct node ;p 2 < element n : struct node ;r : n > p *U data : r>p: p > p *U ne/t : free . r 2 : return . n 2 : D int isempty . struct node ;p 2 < if . p >> 8SOO 2 return . *1 2 : else return . % 2 : D 8otice how the specific implementation of the data structure is strewn throughout main. 2. main. 2 must see the definition of the structure node to use the push. 2, pop. 2, and other stack functions. Thus the implementation is not hidden, but is mi/ed with the abstract operations. Data 'tructures 4adi/ 'ort This sorting techni)ue is based on the values of the actual digits in the positional representations of the numbers being sorted. Ssing the decimal base, for e/ample, where the radi/ is 1%, the numbers can be partitioned into ten groups on the sorter. -or e/ample, to sort a collection of numbers where each number is a four*digit number, then, 3ll the numbers are first sorted according to the the digit at unitHs place. In the second pass, the numbers are sorted according to the digit at tenth place. In the third pass, the numbers are sorted according to the digit at hundredth place. In the forth and last pass, the numbers are sorted according to the digit at thousandth place. During each pass, each number is taken in the order in which it appears in partitions from unitHs place onwards. &hen these actions have been performed for each digit, starting with the least significant and ending with most significant, the numbers are sorted. This sorting method is called the radi/ sort. Oet us take another e/ample. 'uppose we have a list of names. To sort these names using radi/ sort method we will have to classify them into 2J groups The list is first sorted on the first letter of each name, i.e. the names are arranged in 2J classes, where the first class consists of those names that begin with alphabet H3H, the second class consists of those names that begin with alphabet HGH and so on. During the second pass each class is alphabetized according to the second letter of the name, and so on. $9.

#isit

http!""www.downloadmela.com"

for more papers

Exception Handling in C ,onsider the following program! 5include ?math.hU void main. 2 < float i : i > pow . *2, 7 2 : printf . ACfA, i 2 : D int matherr . struct e/ception ;a 2 < if . a *U type >> DK63I8 2 < if . Wstrcmp . a *U name, ApowA 2 2 < a *U retval > pow . * . a *U arg1 2, a *U arg2 2 : return 1 : D D return % : D If we pass a negative value in pow. 2 function a run time error occurs. If we wish to get the proper output even after passing a negative value in the pow. 2 function we must handle the run time error. -or this, we can define a function matherr. 2 which is declared in the Hmath.hH file. In this function we can detect the run*time error and write our code to correct the error. The elements of the e/ception structure receives the function name and arguments of the function causing the e/ception. Data 'tructures 3#O Trees -or ideal searching in a binary search tree, the heights of the left and right sub*trees of any node should be e)ual. Gut, due to random insertions and deletions performed on a binary search tree, it often turns out to be far from ideal. 3 close appro/imation to an ideal binary search tree is achievable if it can be ensured that the difference between the heights of the left and the right sub trees of any node in the tree is at most one. 3 binary search tree in which the difference of heights of the right and left sub*trees of any node is less than or e)ual to one is known as an 3#O tree. 3#O tree is also called as Galanced Tree. The name A3#O TreeA is derived from the names of its inventors who are 3delson*#eilskii and Oandi. 3 node in an 3#O tree have a new field to store the Abalance factorA of a node which denotes the difference of height between the left and the right sub*trees of the tree rooted at that node. 3nd it can assume one of the three possible values <*1,%,1D. #isit

http!""www.downloadmela.com"

for more papers

************************************************************************************************* $T. ni!"e combinations for a gi#en n"mber Ho$ do I $rite a program $hich can generate all possible combinations of n"mbers from % to one less than the gi#en n"mber ? main. 2 < long steps, fval, bstp, cnt1 : int num, unit, bo/0210171, cnt2, cnt7, cnt9 : printf . A(nter 8umber A 2 : scanf . ACdA, Qnum 2 : num > num ? 1 F 1 ! num U 12 F 12 ! num : for . steps > 1, cnt1 > 2 : cnt1 ?> num : steps ;> cnt1@@ 2 : for . cnt1 > 1 : cnt1 ?> steps : cnt1@@ 2 < for . cnt2 > 1 : cnt2 ?> num : cnt2@@ 2 bo/0%10cnt21 > cnt2 : for . fval > steps, bstp > cnt1, cnt2 > 1 : cnt2 ?> num : cnt2@@ 2 < if . bstp >> % 2 < cnt9>num : while . bo/0%10cnt91 >> % 2 cnt9** : D else < fval "> num * cnt2 @ 1 : unit > . bstp @ fval * 1 2 " fval : bstp C> fval : for . cnt9 > %, cnt7 > 1 : cnt7 ?> unit : cnt7@@ 2 while . bo/0%10@@cnt91 >> % 2 : D bo/0110cnt21 > bo/0%10cnt91 : bo/0%10cnt91 > % : D printf . ABn'e).8o.Cld!A, cnt1 2 : for . cnt2 > 1 : cnt2 ?> num : cnt2@@ 2 printf . A CdA, bo/0110cnt21 2 : D D This program computes the total number of steps. Gut instead of entering into the loop of the first and last combination to be generated it uses a loop of 1 to number of combinations. -or e/ample, in case of input being T the number of possible combinations would be factorial T, i.e. 12%. The program suffers #isit

http!""www.downloadmela.com"

for more papers

from the limitation that it cannot generate combinations for input beyond 12 since a long int cannot handle the resulting combinations. Data 'tructures +ashing... +ashing or hash addressing is a searching techni)ue. Ssually, search of an element is carried out via a se)uence of comparisons. +ashing differs from this as it is independent of the number of elements n in the collection of data. +ere, the address or location of an element is obtained by computing some arithmetic function. +ashing is usually used in file management. The general idea is of using the key to determine the address of a record. -or this, a function fun. 2 is applied to each key, called the hash function. 'ome of the popular hash functions are! HDivisionH method, H6ids)uareH method, and H-oldingH method. Two records cannot occupy the same position. 'uch a situation is called a hash collision or a hash clash. There are two basic methods of dealing with a hash clash. The first techni)ue, called rehashing, involves using secondary hash function on the hash key of the item. The rehash function is applied successively until an empty position is found where the item can be inserted. If the hash position of the item is found to be occupied during a search, the rehash function is again used to locate the item. The second techni)ue, called chaining, builds a linked list of all items whose keys hash to the same values. During search, this short linked list is traversed se)uentially for the desired key. This techni)ue involves adding an e/tra link field to each table position. ************************************************************************************************* $J. &he follo$ing program demonstrates ho$ to get inp"t from the "ser in graphics mode' echoed in the c"rrent colors and font si(e and font style) 5define K8 1 5define K-- % 5include ?graphics.hU main. 2 < char name'tring0$%1, age'tring0$%1 : int age, gd > D(T(,T, gm : initgraph . Qgd, Qgm, Ac!BBtcBBbgiA 2 : setbkcolor . GOS( 2 : setcolor . Y(OOK& 2 : sette/tstyle . LKT+I,X-K8T, +K4IMXDI4, % 2 : moveto . %, % 2 : outte/t . A(nter your name! A 2 : getLr'tring . name'tring 2 : moveto . %, gety. 2 @ te/theight . A3A 2 2 : outte/t . A8ame! A 2 : outte/t . name'tring 2 : moveto . %, gety. 2 @ te/theight . A3A 2 2 : #isit

http!""www.downloadmela.com"

for more papers

outte/t . A ress key to e/itW A 2 : getch. 2 : closegraph. 2 : restorecrtmode. 2 : D getLr'tring . char ;input'tring 2 < int stringInde/ > %, old,olor : char ch, out'tring021 : "; /#al will store the screen position for each char ;" int /#al02TT1 : out'tring011 > % : /#al0%1 > get/. 2 : do < cursor . K8 2 : ch > getch. 2 : cursor . K-- 2 : if . ch >> % 2 "; avoid dealing with all special keys ;" getch. 2 : else < if . ch >> $ 2 "; backspace ;" < old,olor > getcolor. 2 : **stringInde/ : if . stringInde/ ? % 2 stringInde/ > % : "; move to . old horz position, current vert position 2 ;" moveto . /#al0stringInde/1, gety. 2 2 : setcolor . getbkcolor. 2 2 : out'tring0%1 > input'tring0stringInde/1 : outte/t . out'tring 2 : moveto . /#al 0stringInde/1, gety. 2 2 : setcolor . old,olor 2 : D else < input'tring0stringInde/1 > ch : out'tring0%1 > ch : outte/t . out'tring 2 : @@stringInde/ : /#al0stringInde/1 > get/. 2 : D D D while . ch W> 17 QQ ch W> 1% 2 : #isit

http!""www.downloadmela.com"

for more papers

input'tring0stringInde/1 > % : D cursor . int on 2 < int curV, old,olor : "; weHll use an underscore as a cursor ;" char uGar'tr021 > < HXH, % D : if . Won 2 < old,olor > getcolor. 2 : setcolor . getbkcolor. 2 2 : D "; save horizontal position before drawing cursor ;" curV > get/. 2 : outte/t . uGar'tr 2 : moveto . curV, gety. 2 2 : "; if we changed the color to erase cursor, change it back ;" if . Won 2 setcolor . old,olor 2 : D The function getLr'tring. 2 echoes graphically the user input and stores it in a buffer, and the function cursor. 2 handles the cursor position. 'ystem Stility &hat is garbage collectionF 3ns! 'uppose some memory space becomes reusable because a node is released from a linked list. +ence, we want the space to be available for future use. Kne way to bring this about is to immediately reinsert the space into the free*storage list. +owever, this method may be too time*consuming for the operating system. The operating system may periodically collect all the deleted space onto the free* storage list. The techni)ue that does this collection is called Larbage ,ollection. Larbage ,ollection usually takes place in two steps! -irst the Larbage ,ollector runs through all lists, tagging whose cells are currently in use, and then it runs through the memory, collecting all untagged space onto the free* storage list. The Larbage ,ollection may take place when there is only some minimum amount of space or no space at all left in the free*storage list, or when the , S is idle and has time to do the collection. Lenerally speaking, the Larbage ,ollection is invisible to the programmer. $E. Ho$ do I get the time elapsed bet$een t$o f"nction calls ? 3ns! The function difftime. 2 finds the difference between two times. It calculates the elapsed time in seconds and returns the difference between two times as a double value. 5include ?time.hU #isit

http!""www.downloadmela.com"

for more papers

5include ?stdio.hU 5include ?dos.hU main. 2 < int a01 > < 2, *79, TJ, E$, 112, 77, *E, 11, 9T, 2Z, J D : int s : timeXt t1, t2 : "" timeXt defines the value used for time function s > sizeof . a 2 " 2 : t1 > time . 8SOO 2 : selXsort . a, s 2 : "" sort array by selection sort bubXsort . a, s 2 : "" sort array by bubble sort method t2 > time . 8SOO 2 : printf . ABnThe difference between two function calls is CfA, difftime . t2, t1 2 2 : D In the above program we have called difftime. 2 function that returns the time elapsed from t1 to t2. ************************************************************************************************* $$. Leneral main. 2 < char ;s : s > fun . 12$, 2 2 : printf . ABnCsA, s 2 : D fun . unsigned int num, int base 2 < static char buff0771 : char ;ptr : ptr > Qbuff 0 sizeof . buff 2 * 1 1 : ;ptr > HB%H : do < ;**ptr > A%1279TJE$ZabcdefA0 num C base 1 : num "> base : D while . num W> % 2 : return ptr : D The above program would convert the number 12$ to the base 2. You can convert a number to a he/adecimal or octal form by passing the number and the base, to the function fun. 2. Data 'tructures #isit

http!""www.downloadmela.com"

for more papers

&hat is a priority )ueueF 3ns! 3s we know in a stack, the latest element is deleted and in a )ueue the oldest element is deleted. It may be re)uired to delete an element with the highest priority in the given set of values and not only the oldest or the newest one. 3 data structure that supports efficient insertions of a new element and deletions of elements with the highest priority is known as priority )ueue. There are two types of priority )ueues! an ascending priority )ueue is a collection of items into which items can be inserted arbitrarily and from which only the smallest item can be removed. 3 descending order priority )ueue is similar but allows only the largest item to be deleted. ************************************************************************************************* $Z. What is the difference bet$een const char *p' char const *p' and char* const p ? Hconst char ;pH and Hchar const ;pH are the same, i.e. p points to a constant character. Kn the other hand, Hchar; const pH means p is a constant pointer pointing to a character which means we cannot change the pointer p but we can change the character which p is pointing to. ************************************************************************************************* Z%. What+s the difference bet$een a n"ll pointer' a , -- macro' the A.CII , - character and a n"ll string? 3ns! 3 null pointer is a pointer which doesnHt point anywhere. 3 8SOO macro is used to represent the null pointer in source code. It has a value % associated with it. The 3',II 8SO character has all its bits as % but doesnHt have any relationship with the null pointer. The null string is =ust another name for an empty string AA. 'ystem Stility 'parse 6atri/... 3 sparse matri/ is one where most of its elements are zero. There is no precise definition as to know whether a matri/ is sparsed or not, but it is a concept which we all can recognize intuitively. The natural method of representing matrices in memory as two*dimensional arrays may not be suitable for sparse matrices. That is one may save space by storing only those entries which may be nonzero. If this is done, then the matri/ may be thought of as an ordered list of non*zero elements only. Information about a non*zero element has three parts! an integer representing its row, an integer representing its column and the data associated with this element. That is, each element of a matri/ is uni)uely characterized by its row and column position, say i, =. &e might store that matri/ as a list of 7*tuples of the form .i, =, data2, as shown below,

#isit

http!""www.downloadmela.com"

for more papers

3lthough the non*zero elements may be stored in the array in any order, keeping them ordered in some fashion may be advantageous for further processing. 8ote that above array is arranged in increasing order of the row number of non*zero elements. 6oreover, for elements in the same row number, the array is arranged in order of increasing column number. ************************************************************************************************* Z1. ointers What does the error /,"ll 0ointer Assignment/ mean and $hat ca"ses this error? 3ns! The 8ull ointer 3ssignment error is generated only in small and medium memory models. This error occurs in programs which attempt to change the bottom of the data segment. In GorlandHs , or ,@ @ compilers, Gorland places four zero bytes at the bottom of the data segment, followed by the Gorland copyright notice AGorland ,@@ * ,opyright 1ZZ1 Gorland Intl.A. In the small and medium memory models, a null pointer points to D'!%%%%. Thus assigning a value to the memory referenced by this pointer will overwrite the first zero byte in the data segment. 3t program termination, the four zeros and the copyright banner are checked. If either has been modified, then the 8ull ointer 3ssignment error is generated. 8ote that the pointer may not truly be null, but may be a wild pointer that references these key areas in the data segment. Data 'tructures Ho$ to b"ild an expression trees ? 3ns! 3n e/pression tree is a binary tree which is built from simple operands and operators of an .arithmetic or logical 2 e/pression by placing simple operands as the leaves of a binary tree and the operators as the interior nodes. If an operator is binary , then it has two nonempty subtrees, that are its left and right operands .either simple operands or sub e/pressions2. If an operator is unary, then only one of its subtrees is nonempty, the one on the left or right according as the operator is written on the right or left of its operand. &e traditionally write some unary operators to the left of their operands, such as A*A . unary negation2 or the standard functions like log. 2, sin. 2 etc. Kthers are written on the right, such as the factorial function .2W. If the operator is written on the left, then in the e/pression tree we take its left subtree as empty. If it appears on the right, then its right subtree will be empty. 3n e/ample of an e/pression tree is shown below for the e/pression . *a ? b 2 or . c @ d 2 . ************************************************************************************************* Z2. Can $e get the remainder of a floating point di#ision ? 3ns ! Yes. 3lthough the C operator fails to work on float numbers we can still get the remainder of floating point division by using a function fmod. 2. The fmod. 2 function divides the two float numbers passed to it as parameters and returns the remainder as a floating*point value. -ollowing program shows fmod. 2 function at work. 5include ?math.hU #isit

http!""www.downloadmela.com"

for more papers

main. 2 < printf . ACfA, fmod . T.1T, 7.% 2 2 : D The above code snippet would give the output as 2.1T%%%%. ************************************************************************************************* Z7. Ho$ to extract the integer part and a fractional part of a floating point n"mber? 3ns! , function modf. 2 can be used to get the integer and fractional part of a floating point. 5include Amath.hA main. 2 < double val, i, f : val > T.1T : f > modf . val, Qi 2 : printf . ABn-or the value Cf integer part > Cf and fractional part > CfA, val, i, f 2 : D The output of the above program will be! -or the value T.1T%%%% integer part > T.%%%%%% and fractional part > %.1T%%%% Z9. Ho$ do I define a pointer to a f"nction $hich ret"rns a char pointer? 3ns! char ; . ;p 2. 2 : or typedef char ; . ; ptrtofun 2. 2 : ptrtofun p : +ere is a sample program which uses this definition. main. 2 < typedef char ; . ; ptrtofun 2 . 2 : char ; fun. 2 : ptrtofun fptr : char ;cptr : fptr > fun : #isit

http!""www.downloadmela.com"

for more papers

cptr > .;fptr2 . 2 : printf . ABn4eturned string is BACsBAA, cptr 2 : D char ; fun. 2 < static char s0 1 > A+elloWA : printf . ABnCsA, s 2 : return s : D ************************************************************************************************* ZT. What+s $rong $ith the follo$ing declaration1 char* ptr%' ptr2 3 get errors $hen I try to "se ptr2 as a pointer) 3ns! char ; applies only to ptr1 and not to ptr2. +ence ptr1 is getting declared as a char pointer, whereas, ptr2 is being declared merely as a char. This can be rectified in two ways ! char ;ptr1, ;ptr2 : typedef char; ,+34 T4 : ,+34 T4 ptr1, ptr2 : ************************************************************************************************* ZJ. Ho$ to "se scanf4 5 to read the date in the form of dd6mm6yy? 3ns! To read the date in the form of dd*mm*yy one possible way is, int dd, mm, yy : char ch : "; for char H*H ;" printf . ABn(nter the date in the form of dd*mm*yy ! A 2 : scanf. ACdCcCdCcCdA, Qdd, Qch, Qmm, Qch, Qyy 2 : 3nother way is to use suppression character ; is as follows! int dd, mm, yy : scanf. ACdC;cCdC;cCdA, Qdd, Qmm, Qyy 2 : The suppression character H;H suppresses the input read from the standard input buffer for the assigned control character. ************************************************************************************************* ZE. Why the o"tp"t of si(eof 4 +a+ 5 is 2 and not % ? 3ns! ,haracter constants in , are of type int, hence sizeof . HaH 2 is e)uivalent to sizeof . int 2, i.e. 2. +ence the output comes out to be 2 bytes. ************************************************************************************************* Z$. Can $e "se scanf4 5 f"nction to scan a m"ltiple $ords string thro"gh keyboard? 3ns! Yes. 3lthough we usually use scanf. 2 function to receive a single word string and gets. 2 to #isit

http!""www.downloadmela.com"

for more papers

receive a multi*word string from keyboard we can also use scanf. 2 function for scanning a multi*word string from keyboard. -ollowing program shows how to achieve this. main. 2 < char buff01T1 : scanf . AC0[Bn1sA, buff 2 : puts . buff 2 : D In the scanf. 2 function we can specify the delimiter in brackets after the [ character. &e have specified HBnH as the delimiter. +ence scanf. 2 terminates only when the user hits (nter key. ************************************************************************************************* ZZ. Ho$ to set the system date thro"gh a C program ? 3ns! &e can set the system date using the setdate. 2 function as shown in the following program. The function assigns the current time to a structure date. 5include Astdio.hA 5include Ados.hA main. 2 < struct date newXdate : newXdate.daXmon > 1% : newXdate.daXday > 19 : newXdate.daXyear > 1ZZ7 : setdate . QnewXdate 2 : D ************************************************************************************************* 1%%. Ho$ can I $rite a general6p"rpose s$ap $itho"t "sing templates? 3ns! Liven below is the program which uses the stringizing preprocessor directive 55 for building a general purpose swap macro which can swap two integers, two floats, two chars, etc. 5define swap. a, b, t 2 . g 55 t > . a 2, . a 2 > . b 2, . b 2 > g 55 t 2 int gint: char gchar: float gfloat : main. 2 #isit

http!""www.downloadmela.com"

for more papers

< int a > 1%, b > 2% : char ch1 > HaH , ch2 > HbH : float f1 > 1.12, f2 > 7.19 : swap . a, b, int 2 : printf . ABna > Cd b > CdA, a, b 2 : swap . ch1, ch2, char 2 : printf . ABnch1 > Cc ch2 > CcA, ch1, ch2 2 : swap . f1, f2, float 2 : printf . ABnf1 > C9.2f f2 > C9.2fA, f1, f2 2 : D swap . a, b, int 2 would e/pand to, . gint > . a 2, . a 2 > . b 2, . b 2 > gint 2 ************************************************************************************************* 1%1. What is a heap ? 3ns ! +eap is a chunk of memory. &hen in a program memory is allocated dynamically, the , run* time library gets the memory from a collection of unused memory called the heap. The heap resides in a programHs data segment. Therefore, the amount of heap space available to the program is fi/ed, and can vary from one program to another. 1%2. Ho$ to obtain a path of the gi#en file? 3ns! The function searchpath. 2 searches for the specified file in the subdirectories of the current path. -ollowing program shows how to make use of the searchpath. 2 function. 5include Adir.hA void main . int argc, char ;argv01 2 < char ;path : if . path > searchpath . argv0 1 1 2 2 printf . A athname ! CsBnA, path 2 : else printf . A-ile not foundBnA 2 : D ************************************************************************************************* 1%7. Can $e get the process identification n"mber of the c"rrent program? 3ns! YesW The macro getpid. 2 gives us the process identification number of the program currently running. The process id. uni)uely identifies a program. Snder DK', the getpid. 2 returns the rogram #isit

http!""www.downloadmela.com"

for more papers

'egment refi/ as the process id. -ollowing program illustrates the use of this macro. 5include ?stdio.hU 5include ?process.hU void main. 2 < printf . AThe process identification number of this program is CVBnA, getpid. 2 2 : D *************************************************************************************************

1%9. Ho$ do I $rite a f"nction that takes #ariable n"mber of arg"ments? 3ns! The following program demonstrates this. 5include ?stdio.hU 5include ?stdarg.hU void main. 2 < int i > 1% : float f > 2.T : char ;str > A+elloWA : vfpf . ACd Cf CsBnA, i, f, str 2 : vfpf . ACs CsA, str, A+iWA 2 : D void vfpf . char ;fmt, ... 2 < vaXlist argptr : vaXstart . argptr, fmt 2 : vfprintf . stdout, fmt, argptr 2 : vaXend . argptr 2 : D +ere, the function vfpf. 2 has called vfprintf. 2 that take variable argument lists. vaXlist is an array that holds information re)uired for the macros vaXstart and vaXend. The macros vaXstart and vaXend provide a portable way to access the variable argument lists. vaXstart would set up a pointer argptr to point to the first of the variable arguments being passed to the function. The macro vaXend helps the called function to perform a normal return. ************************************************************************************************* #isit

http!""www.downloadmela.com"

for more papers

1%T. Can $e change the system date to some other date? 3ns! Yes, &e canW The function stime. 2 sets the system date to the specified date. It also sets the system time. The time and date is measured in seconds from the %%!%%!%% L6T, \anuary 1, 1ZE%. The following program shows how to use this function. 5include ?stdio.hU 5include ?time.hU void main. 2 < timeXt tm : int d : tm > time . 8SOO 2 : printf . AThe 'ystem Date ! CsA, ctime . Qtm 2 2 : printf . ABn+ow many days ahead you want to set the date ! A 2 : scanf . ACdA, Qd 2 : tm @> . 29O ; d 2 ; J%O ; J%O : stime . Qtm 2 : printf . ABn8ow the new date is ! CsA, ctime . Qtm 2 2 : D In this program we have used function ctime. 2 in addition to function stime. 2. The ctime. 2 function converts time value to a 2J*character long string that contains date and time. ************************************************************************************************* 1%J. Ho$ to "se f"nction strd"p4 5 in a program? 3ns ! The string function strdup. 2 copies the given string to a new location. The function uses malloc. 2 function to allocate space re)uired for the duplicated string. It takes one argument a pointer to the string to be duplicated. The total number of characters present in the given string plus one bytes get allocated for the new string. 3s this function uses malloc. 2 to allocate memory, it is the programmer]s responsibility to deallocate the memory using free. 2. 5include ?stdio.hU 5include ?string.hU 5include ?alloc.hU void main. 2 < char ;str1, ;str2 > AdoubleA: str1 > strdup . str2 2 : #isit

http!""www.downloadmela.com"

for more papers

printf . ACsBnA, str1 2 : free . str1 2 : D ************************************************************************************************* 1%E. 7n incl"ding a file t$ice I get errors reporting redefinition of f"nction) Ho$ can I a#oid d"plicate incl"sion? 3ns! 4edefinition errors can be avoided by using the following macro definition. Include this definition in the header file. 5if Wdefined filenameXh 5define filenameXh "; function definitions ;" 5endif 4eplace filenameXh with the actual header file name. -or e/ample, if name of file to be included is Hgoto.hH then replace filenameXh with HgotoXhH. ************************************************************************************************* 1%$. Ho$ to $rite a s$ap4 5 f"nction $hich s$aps the #al"es of the #ariables "sing bit$ise operators) 3ns! +ere is the swap. 2 function. swap . int ;/, int ;y 2 < ;/ [> ;y : ;y [> ;/ : ;/ [> ;y : D The swap. 2 function uses the bitwise VK4 operator and does not re)uire any temporary variable for swapping.

#isit

http!""www.downloadmela.com"

for more papers

You might also like