# i nc l ude# i nc l ude # i nc l ude v oi dNe wT e xt ( c ha rs t r [] , i nt& pos ) { c ha r*p=s t r ; i ntl e ngt h=s t r l e n( p) ; f or (; pos
} 4 8Wha ti st heout puto ft hef o l l o wi ngpr o gr a m(As s umea l lne c e s s a r yhe a de rfil e sa r e i nc l ude d): #i nc l ude #i nc l ude# i nc l ude # i nc l udec l a s sc ount r y { c har*c _name; i ntl e ngt h; publ i c : c o unt r y() { l e ng t h=0 ; c _name=newc har [ l engt h+1] ; } c o unt r y( c ha r*s ) { l e ngt h=s t r l e n( s ) ; c _name=newc har [ l engt h+1] ; s t r c py( c _ na me ,s ) ; } v oi ddi s pl a y( ) { c out <
c 3. di s pl a y() ; ge t c h() ; }
e1 Ehat will be the output of the following program: [*! -includeiostream.h/ -includectype.h/ -includeconio.h/ -includestring.h/ &oid >ointersLun0char ext[!, intointersLun0Mata, position1"
coutMata DNB position" cout.write0Mata ? *, 1" $ 12Consi de rt hef o l l o wi ngs t a t e me nt s Cha rc h , c h 1=’ A’ ; Char* p, * p1=&ch1; *p1=ch1+1; *p=ch; S uppo s ee a c hc h ar a c t e ro c c u pi e s2b yt e so fme mo r y . I ft heva l uea s s i gne dt oc hi ss t o r e di n a ddr e s s0 x 22a ndt hev al uea s s i gne dt oc h 1i ss t o r e di na ddr e s s0 x 10 5t he n ( i )wha tv al uei sa s s i gne dt op1 ; ( i i )wha ti st heva l ueof* p1 ; ( i i i )wha tv a l uei sa s s i gne dt oc h? ( i v)Wha tv al uei sa s s i gne dt o* p?
e )F i ndt hec o r r e c tpos s i bl eo ut puto ft hef o l l o wi ngpr o gr a m (Cons i de ra l lt hehe a de r fil e sa r epr e s e nt ). s t r uc tc ar d{ c ha rs ui t [ 1 0] ; i ntdi gi t ; } ; car d*ca r ds=newcar d[ 52] ;//Al l ocat eMemory v oi dc r e a t e de c k( ) {
chart emp[ ] [ 10]={ " Cl ubs" , " Spades " , " Di amonds " , " Hear t s " } ; i nti , m=0 , c nt =1 ; f or ( i =1 ; i <=5 2; i ++) {
s t r c py( c ar ds [ i ] . s ui t , t emp[ m] ) ; c ar ds [ i ] . di gi t =c nt ; cnt++; i f ( i% 1 3==0 ) {m++;c nt =1; } }}
car ddr awcar d( i ntnum) {
i ntr ndnum; r a ndo mi z e ( ) ; r ndnum =r a ndom( num) +1; r e t ur n( c a r ds [ r ndnum] ) ;
} voi dmai n( ) {
c r e at e de c k( ) ; c a r dc ; c=dr a wc a r d( 3 9 ) ; i f ( c . di gi t>1 0||c . di gi t==1 ) {
s wi t c h( c . di gi t ) {
c as e11 :
c out <<" J ac kof" ; br e a k;
c as e12 :
c out <<" Que e nof" ;br e a k;
c as e13 :
c out <<" Ki ngof" ; br e ak;
c as e1 :
c out <<" Ac eof" ;
}} e l s e c out <
i )
Ki ndofSpade s
i i i ) Ac eofDi amond
i i )
Ac eofCl ubs
i v)
Que e nofHe a r t s
4 1 .Gi v et heo ut putoft hef o l l o wi ngpr o gr a m(As s umea l lne c e s s a r yhe a de rfil e sa r e i nc l ude d) : voi dmai n() { c har*x=“t eAmI ndi a”; c ha rc ; c=++(* ( x +1 )) ; cout<
17Whatwi l lbet heout putoft hef ol l owi wi ngpr ogr am: m: # i nc l ude # i nc l ude# i nc l ude # i nc l ude v oi dc ha ng es t r i ng( c ha rt e xt [ ] ,i nt&c ount e r ) { c ha r* p t r=t e xt ; i ntl e ngt h=s t r l e n( t e xt ) ; f or (; c o unt e r#include #include #include void main() { clrscr(); char * NAM ! "a ro$i%e"; &or (int ' ! ;' #include #include #include void main() { clrscr(); char *s ! "3445%678"; &or (int ' ! strlen(s)01 ; '>!; '00) { &or ( int y!; y
cout<#include #include #include void main() { int a ! 9: * ! a; char ch ! =: eco ! ch; eco ! a; * ! ch; cout << a << ?:? << ch << endl; 2 #include #include #include #include void Nete't(char @tring+,: int osition) { char *ointer ! @tring; int %ength ! strlen(@tring); &or ( ; osition<%ength 0 ; osition!: ointer) { *(ointerosition) ! toupper(*(ointer osition)); 2 2 void main() { clrscr(); int %ocation ! ; char Message+, ! "5ynamic Act"; Act"; Nete't(Message: Nete't(Message: %ocation); cout << Message << " # " << %ocation; 2 #include void main() int '+, ! {1: : 9: :2; int *p: **B: *t; p ! '; t ! ' 1; B ! t; cout<<*p<<":"<<**B<<":"<<*t; 2 #include #include struct 3ame { char Mag+,; int @core; 2; void main() { clrscr(); 3ame M!{"Ciger": 2; char *7hoice; 7hoice ! M.Mag; 7hoice+, ! ??; 7hoice+, ! ?%?; M.@core!; cout << M.Mag << M.@core << endl; 3ame N ! M;
{
N.Mag+, ! ?A?; N.Mag+9, ! ?D?; N.@core 0! 1; cout << N.Mag << N.@core << endl; 2
Q1( i ) Fi ndt hemi mi st ake,i fanyi nt hef ol l owi ngdefini t i on andma maket he necessary corr ect i ons: c har* pt r,s [ 10] ; pt r=s [ 6] ; ( i i )
Di s t i ngui shbet we en: i nt*pt r=ne wi nt ( 5) ; i nt* p t r=ne wi nt [ 5] ;
Q2
Gi v ent hef ol l owi ngdec l ar at i ons: i nt i v al =2048; i nt * i pt r ; doubl e* dpt r ; Whi c ho ft hef ol l o wi wi ngas s i g nme nt s, i fany,ar ei l l e g al? Expl ai nwhy? ( a)i val=* i pt r ;
Q3
( b) * i pt r=&i val
( c)* i pt r=i val ( d)dpt r=i pt r
I fARR i sanarr ayofi nt eg er s,whyi st heexpr es si on ARR++i s no tl e gal?
Q4
Di ffer ent i at ebe t wee nSt at i candDynami mi cal l oc at i onofmemo mor y .
Q5
Whatdoyou under s t and byme memor yl eaks?W Wh hatar epos si bl er eas onsf ori t? How canme memo mor yl eaksbeav oi ded?
Q6
Whati st hi spoi nt er?Wh Whati si tsi gni ficance?
3 8 .Wr i t eaf unc t i onwhi c ht a ke sp oi nt e r st ot wos t r i ngsa spa r a m me e t e ra ndc o mp mpa r et he s e s t r i ngs . Thef unc t i ons h oul dr e t ur n1i ft wos t r i ngsa r es a me meot he r wi s er e t ur n0 .
Q7
How doe st hef unct i oni ngofaf unct i ondi fferwhen ( i ) ( i i ) ( i i i )
anobj ecti spas sedbyval ue anobj ec ti spassedbyre f er ence an obj ecti spassedbypoi nt er
Q8
Expl ai nse l fr ef er ent i als t r uct ur eswi t hexampl e.
Q9
Whatdoest hi spoi nt erdo?Whatar et heappl i cat i onoft hi spoi nt er?
Q10 Definet hes t r i ngcl asshavi ngf ol l owi ngmemberf unct i ons: ( a) ( b) ( c) ( d) ( e)
upcas e() l owcase() l engt h() scopy() sconc at ()
: : : :
Thatconv er t st hes t r i ngi nt oupper cas e : Thatconve r tt hest r i ngt ol ower case Thatcal cul at est hel engt hofs t r i ng Tocopyt hes t r i ng Toconc at enat et wos t r i ngs
DEC (D6@C EN CN MEN6C@) 1.
Wr i t east at ementt hatdi spl ayst headdr essoft hev ari abl et es t var . _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2.
Thecont ent soft wopoi nt er st hatpoi ntt oadj acentvar i abl eoft ypefloat di fferby____ ____ __
3.
Apoi nt eri s
4.
1.an addr essoft hevar i abl e 2.an i ndi cat i onoft hevari abl et obeaccessednext 3.avari abl eofst ori ngaddr ess 4.Thedat at ypeofanaddr essvar i abl e. I nasel fr ef er ent i alst r uct ur e
5.
1.eachl i nkcont ai nsapoi nt ert ot henextl i nk 2.anarr ayofpoi nt er spoi ntt ot hel i nks 3.eachl i nkcont ai nsdat aorpoi nt ert odat a 4.t hel i nksarest or edi nan arr ay Thene w ope r at or
6.
1.r et ur nsapoi nt ert oavari abl e 2.cr eat esavari abl ecal l ednew 3.obt ai nsmemor yf oranew v ar i abl e 4.t el l show muchmemor yi sav ai l abl e Thefir s tel ementi nas t r i ngi s 1.Thenameo ft hes t r i ng 2.Thefir stcharact eri nt hest r i ng 3.Thel engt hoft hest r i ng
7.
4.t henameoft hearr ayhol di ngt hest r i ng Thee xpr ess i on* t es tcanbes ai dt o
8.
1.beapoi nt ert onext 2.r e f e rt ot hec o nt e nto ft e s t 3.der ef er encet est 4.r e f e rt ot hev al ueoft hev ar i abl epo i nt e dt obyt e s t Usi ngnew mayr es ul ti nl es s__ __ __ __ __ __ _ __ __ __memor yt hanusi ngan ar r ay .
9
Thedel et eoper at orr et ur ns__ __ __ __ __ __ __ __ __ __ _t ot heoper at i ngsy st em.
10.
Gi ve napoi nt erpt hatpoi nt st oanobj ectoft ypeupper cl ass,wr i t ean expr essi on t hatexecut est heexcl u()memberf unct i on i nt hi sobj ect . _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
11.
Wr i t eadefini t i onf oranarr aynumpt r sofpoi nt er st ot hes t r i ngs“ One”, “ t wo”
and “Thr ee” . _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
12.
Usi ngpoi nt ernot at i on wri t et hepr ot ot ypef oraf unct i on cal l edr evst r ()t hat r et ur nsast r i ngval ueandt akesoneargumentt hatr epr esent sast r i ng. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
13.
Usi ngpoi nt ernot at i onwr i t ecodet hatwi l lt r ansf er80charact er sf r om t he s t r i ngs1t ot hes t r i ngs 2. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
14.
Usi ngpoi nt ernot at i onwri t eapr ot ot ypedecl arat i onf oraf unct i oncal l ed f unc ()t hatr et urnst ypev oi d andt akesasi ngl ear gumentt hati san arr ayoft ype char. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
15. Oft het hr eewayst opassar gument st of unct i ons,onl ypassi ngby ____ ____ ____ _____ andpassi ng
by____ _____ ____ ____ _al l ow thef unct i on t o
modi f yt hear gumenti nt hecal l i ngpr ogr am.