Sie sind auf Seite 1von 304

Pointers tutorial in c

Understanding pointers in c Definition How to read complex pointers Arithmetic operation with pointers Pointer to function Pointer to array of function Pointer to array of string Pointer to structure pointer to union Multi level pointer Pointer to array of pointer to string Pointer to three dimentional array Pointer to two dimensional array Sorting of array using pointer Pointer to array of array Pointer to array of union Pointer to array of structure Pointer to array of character Pointer to array of integer Complex pointers Generic pointer ull pointers !ild pointers Dangling pointer ear pointer "ar pointer Graphics video memory #ext video memory Huge pointer Memory model in C

Understanding pointers in c $ntroduction to pointers in c

Pointer is a varia%le &ust li'e other varia%les of c %ut only difference is unli'e the other varia%le it stores the memory address of any other varia%les of c( #his varia%le

may %e type of int) char) array) structure) function or any other pointers( "or examples* +,Pointer p which is storing memory address of a int type varia%le* int i./01 int 2p.3i1 +4Pointer p which is storing memory address of an array* int arr54061 int +2p-5406.3arr1 +7Pointer p which is storing memory address of a function* char display+void-1 char+2p-+void-.3display1 +8Pointer p which is storing memory address of struct type varia%le* struct a%c 9 int a1 float %1 : var1 struct a%c 2p.3var1

!hat is pointer in c programming; <xplain pointers in c


Pointer is a user defined data type which creates special types of varia%les which can hold the address of primitive data type li'e char) int) float) dou%le or user defined data type li'e function) pointer etc( or derived data type li'e array) structure) union) enum( <xamples* int 2ptr1 int +2ptr-+-1 int +2ptr-5461

$n c programming every varia%le 'eeps two type of value( ,( Contain of varia%le or value of varia%le( 4( Address of varia%le where it has stored in the memory( +,- Meaning definition* int a./1 int 2 ptr1 ptr.3a1 <xplanation* A%out varia%le a* ,( ame of varia%le * a 4( =alue of varia%le which it 'eeps* / 7( Address where it has stored in memory * ,04/ +assumeA%out varia%le ptr* 8( ame of varia%le * ptr /( =alue of varia%le which it 'eeps* ,04/ >( Address where it has stored in memory * /000 +assumePictorial representation* of following simple pointer declaration and

ote* A varia%le where it will %e stored in memory is decided %y operating system( !e cannot guess at which location a particular varia%le will %e stored in memory( +4- Meaning of following pointer declaration and definition* int a./01 int 2ptr,1 int 22ptr41 ptr,.3a1 ptr4.3ptr,1

<xplanation* A%out varia%le a* ,( ame of varia%le * a 4( =alue of varia%le which it 'eeps* /0 7( Address where it has stored in memory * /000 +assumeA%out varia%le ptr,* 8( ame of varia%le * ptr, /( =alue of varia%le which it 'eeps* /000 >( Address where it has stored in memory * ?000 +assumeA%out varia%le ptr4* @( ame of varia%le * ptr4 A( =alue of varia%le which it 'eeps* ?000 ?( Address where it has stored in memory * ?/// +assumePictorial representation of a%ove pointer declaration and definition*

ote* 2 is 'nown as indirection operator which gives content of any varia%le( 3 is 'nown as reference operator which gives address where varia%le has stored in memory( Cancellation rule of a%ove two operators* 2 and 3 operators always cancel to each other i(e( 23p.p But it is not right to write* 32p.p Simple example* !hat will %e output of following c program; CincludeDstdio(hE

int main +- 9 int x.4/1 int 2ptr.3x1 FFstatement one int 22temp.3ptr1 FFstatement two printf+GHd Hd HdI)x)2ptr)22temp-1 return 01 : Jutput* 4/ 4/ 4/ <xplanation* As we 'now value of varia%le x is 4/( 2ptr. 2+3x- FFfrom statement one .23x .x FFusing cancellation rule .4/ 22temp. 22+3ptr-.2+23ptr-.2ptr.2+3x-.23x.x.4/

How to read complex pointers in C Programming;

Kule ,( Assign the priority considering precedence and following ta%le(

to the pointer declaration associative according to

!here

+-* #his operator %ehaves as %rac'et operator or function operator( 56* #his operator %ehaves as array su%scription operator( 2* #his operator %ehaves multiplication operator( as pointer operator not as

$dentifier* $t is not an operator %ut it is name of pointer varia%le( Lou will always find the first priority will %e assigned to the name of pointer( Data type* $t is also not an operator( Data types also includes modifier +li'e signed int) long dou%le etc(Lou will understand it %etter %y examples* +,- How to read following pointer; char +2 ptr-576 Answer* Step ,* +- and 56 en&oys eMual precedence( So rule of associative will decide the priority( $ts associative is left to right So first priority goes to +-(

Step 4* $nside the %rac'et 2 and ptr en&oy eMual precedence( "rom rule of associative +right to left- first priority goes to ptr and second priority goes to 2(

Step7* Assign third priority to 56(

Step8* Since data type en&oys fourth priority to char(

least

priority

so

assign

ow read it following manner* ptr is pointer to such one dimensional array of siNe three which content char type data( +4- How to read following pointer; float +2 ptr-+intAnswer* Assign the priority considering precedence and associative(

ow read it following manner* ptr is pointer to such function whose parameter is int type data and return type is float type data( Kule 4* Assign the priority of each function separately and read it also separately( Understand it through following example( +7- How to read following pointer; =oid +2ptr-+int +2-546)int +2- +void-Answer* Assign the priority associative( considering rule of precedence and parameter

ow read it following manner* ptr is pointer to such function which first parameter is pointer to one dimensional array of siNe two which content int type data and second parameter is pointer to such function which parameter is void and return type is int data type and return type is void( +8- How to read following pointer; int + 2 + 2 ptr - 5 / 6 - + Answer* Assign the priority associative( considering rule of precedence and

ow read it following manner*

ptr is pointer to such array of siNe five which content are pointerto such function which parameter is void and return type is int type data( +/- How to read following pointer; dou%le2+2+2ptr-+int--+dou%le 22)char cAnswer*

Assign the priority associative(

considering

rule

of

precedence

and

ow read it following manner* ptr is pointer to function which parameter is int type data and return type is pointer to function which first parameter is pointer to pointer of dou%le data type and second parameter is char type data type and return type is pointer to dou%le data type( +>- How to read following pointer; unsigned 22+2+2ptr-5A6+char const 2) (((Answer* Assign the priority associative( considering rule of precedence and

ow read it following manner*

ptr is pointer to array of siNe eight and content of array ispointer to function which first parameter is pointer to character constant and second parameter is varia%le num%er of arguments and return type is pointer to pointer of unsigned int data type(

Arithmetic operation with pointer in c programming


Kule ,* Addition arithmetic with pointers Address O Address P um%er. Address um%er. Address

AddressOO . Address AddressPP . Address OOAddress . Address PPAddress . Address $f we will add or su%tract a num%er from an address result will also %e an address( ew address will %e*

+,-!hat will %e output of following c program; CincludeDstdio(hE int main+-9 int 2ptr.+ int 2-,0001 ptr.ptrO,1 printf+Q HuQ)ptr-1 return 01 :

Jutput* ,004

+4-!hat will %e output of following c program; CincludeDstdio(hE int main+-9 dou%le 2p.+dou%le 2-,0001 p.pO71 printf+Q HuQ)p-1 return 01 : Jutput* ,048

+7-!hat will %e output of following c program; CincludeDstdio(hE

int main+-9 float array5/6.9,(,f)4(4f)7(7f:1 float+2ptr-5/61 ptr.3array1 printf+QHuQ)ptr-1 ptr.ptrO,1 printf+Q HuQ)ptr-1 return 01 : Jutput* ,000 ,040

+8-!hat will %e output of following c program; CincludeDstdio(hE typedef struct a%c9 int far2a1 dou%le %1 unsigned char c1 :ABC1 int main+-9 ABC 2ptr.+ABC 2-,0001 ptr.ptrO41 printf+Q HuQ)ptr-1 return 01 : Jutput* ,04> +out of siNe different different compilerGcc compiler ta'e 8 %yte extra to create structure(#ur%o cO O or other not ta'e that("ar pointer of integer ta'e 8 %yte in tur%o cOO(

+/-!hat will %e output of following c program; CincludeDstdio(hE typedef union a%c9 char near2a1 long dou%le d1 unsigned int i1 :ABC1 int main+-9 ABC 2ptr.+ABC 2-,0001 ptr.ptrP81 printf+Q HuQ)ptr-1 return 01 : Jutput* ?>0

+>-!hat will %e output of following c program; CincludeDstdio(hE float 2 display+int)int-1 int max./1 int main+-9 float 2+2ptr-+int)int-1 ptr.display1 +2ptr-+4)4-1 printf+QHuQ)ptr-1 ptr.ptrO,1 printf+Q HuQ)ptr-1

return 01 : float 2 display+int x)int y-9 float f1 f.xOyOmax1 return 3f1 : Jutput* Compiler error +Due to local varia%le-

Kule 4* Difference arithmetic with pointers Address P Address. um%er $f you will su%tract two pointers result will %e a num%er %ut num%er will not simple mathematical su%traction of two addresses %ut it follow following rule* $f two pointers are of same type then*

Consider following example* CincludeDstdio(hE int main+-9 int 2p.+int 2-,0001

int 2temp1 temp.p1 p.pO41 printf+QHu HuRnQ)temp)p-1 printf+Qdifference. HdQ)pPtemp-1 return 01 : Jutput* ,000 ,008 Difference. 4 <xplanation* Here two pointer p and temp are of same type and %oth are pointing to int data type varai%le( pPtemp . +,008P,000-FsiNeof+int.8F4 .4

+,-!hat will %e output of following c program; CincludeDstdio(hE int main+-9 float 2p.+float 2-,0001 float 2M.+float 2-40001 printf+QDifference. HdQ)MPp-1 return 01 : Jutput* Difference. 4/0 <xplanation* MPp.+4000P,00-FsiNeof+float.,000F8 .4/0

+4-!hat will %e output of following c program; CincludeDstdio(hE struct a%c9 signed char c1 short int i1 long dou%le l1 :1 int main+-9 struct a%c 2p)2M1 p.+struct a%c 2-,0001 M.+struct a%c 2-40001 printf+QDifference. HdQ)MPp-1 return 01 : Jutput* Difference. @> <xplanation* MPp.+4000P,000-FsiNeof+struct a%c.,000F+,O4O,0.,000F,7 .@>

+7-!hat will %e output of following c program; CincludeDstdio(hE typedef union xxx9 char far 2 c1 const volatile i1 long int l1 :SSS1 int main+-9 SSS 2p)2M1

p.+SSS 2-,0001 M.+SSS 2-40001 printf+QDifference. HdQ)MPp-1 return 01 : Jutput* Difference. 4/0 <xplanation* MPp.+4000P,00-Fmax+8)4)8.,000F8 .4/0

+8-!hat

will

%e

output

of

following

program;

CincludeDstdio(hE int main+-9 const volatile array586.90:1 const volatile+2p-586.3array1 const volatile+2M-586.3array1 MOO1 MOO1 printf+QHu HuRnQ)p)M-1 printf+QDifference. HdQ)MPp-1 return 01 : Jutput* ,000 ,0,> +assumeDifference. 4 <xplanation* MPp.+,0,>P,000-FsiNeof+const volatile. ,>F +428.4

Kule 7* $llegal arithmetic with pointers Address Address Address Address !hat O 2 F H Address.$llegal Address.$llegal Address.$llegal Address.$llegal %e output of following c program;

will

CincludeDstdio(hE int main+-9 int i./1 int 2p.3i1 int 2M.+int 2-41 printf+QHdQ)pOM-1 return 01 : Jutput* Compiler error Kule 8* !e can use relation operator and condition operator %etween two pointers( a( $f two pointers are near pointer it will compare only its offset address( !hat will %e output of following c program; CincludeDstdio(hE int main+-9 int near2p.+int near2-0x0A000////1 int near2M.+int near2-0x0A4,,////1 if+p..Mprintf+Q<MuMlQ-1 else printf+Q ot eMualQ-1

return 01 : Jutput* <Mual

%( $f two pointers are far pointer it will compare %oth offset and segment address( !hat will %e output of following c program; CincludeDstdio(hE int main+-9 int far2p.+int far2-0x0A000////1 int far2M.+int far2-0x0A4,,////1 if+p..Mprintf+Q<MuMlQ-1 else printf+Q ot eMualQ-1 return 01 : Jutput* ot eMual

c( $f two pointers are huge pointer it will first normaliNe into the 40 %it actual physical address and compare to its physical address(

!hat will %e output of following c program; CincludeDstdio(hE int main+-9 int huge2p.+int huge2-0x0A000////1 int huge2M.+int huge2-0x0A4,,788/1 if+p..Mprintf+Q<MuMlQ-1 else printf+Q ot eMualQ-1

return 01 : Jutput* <Mual

Kule /* Bit wise arithmetic with pointers !e can perform %it wise operation %etween two pointers li'e Address 3 Address.$llegal Address T Address.$llegal Address U Address.$llegal VAddress.$llegal !hat will %e output of following c program; CincludeDstdio(hE int main+-9 int i./)&.,01 int 2p.3i1 int 2M.3&1 printf+QHdQ)pTM-1 return 01 : Jutput* Compiler error

Kule >* !e can find siNe of a pointer using siNeof operator( !hat will %e output of following c program; CincludeDstdio(hE int main+-9 int near2far2huge2 p1 printf+QHdQ)siNeof+p--1 printf+Q HdQ)siNeof+2p--1

printf+Q HdQ)siNeof+22p--1 return 01 : Jutput* 8 8 4

Pointer to function in c programming


"unction pointer definition* A pointer which 'eeps address of a function is 'nown as function pointer( <xamples of function pointers in c* +,- !hat will %e output if you will execute following code; CincludeDstdio(hE int 2 function+-1 int main+-9 auto int 2x1 int 2+2ptr-+-1 ptr.3function1 x.+2ptr-+-1 printf+QHdQ)2x-1 return 01 : int 2function+-9 static int a.,01 return 3a1 : Jutput* ,0 <xplanation* Here function is function whose parameter is void data type and return type is pointer to int data type( x.+2ptr-+.E x.+23functyion-+- FFptr.3function .E x.function+- FF"rom rule 23p.p .E x.3a So) 2x . 23a . a .,0

+4- !hat will %e output if you will execute following code; CincludeDstdio(hE +"unction can return the other functionint find+char-1 int+2function+--+char-1 int main+-9 int x1 int+2ptr-+char-1 ptr.function+-1 x.+2ptr-+WAW-1 printf+QHdQ)x-1 return 01 : int find+char c-9 return c1 : int+2function+--+char-9 return find1 : Jutput* >/ <xplanation* Here function whose name is function which passing void data type and returning another function whose parameter is char data type and return type is int data type( x.+2ptr-+XAY.E x. +2function +-- +XAY- FFptr.function +FF3find.function +- i(e( return type of function +.E x. +2 3find- +XAY.E x. find +XAY- FF"rom rule23p.p .E x. >/ +7- !hat will %e output if you will execute following code; CincludeDstdio(hE char 2 call+int 2)float 2-1 int main+-9 char 2string1 int a.41 float %.4(0l1 char 2+2ptr-+int2)float 2-1

ptr.3call1 string.+2ptr-+3a)3%-1 printf+QHsQ)string-1 return 01 : char 2call+int 2i)float 2&-9 static char 2str.QcPpointer(%logspot(comQ1 str.strO2iO+int-+2&-1 return str1 : Jutput* inter(%logspot(com <xplanation* Here call is function whose return type is pointer to character and one parameter is pointer to int data type and second parameter is pointer to float data type and ptr is pointer to such function( str. strO2iO +int- +2&.IcPpointer(%logspot(comI O 23aO +int- +23%FFi.3a) &.3% .IcPpointer(%logspot(comI O aO +int- +%.IcPpointer(%logspot(comI O4 O +int- +4(0.IcPpointer(%logspot(comI O8 .Iinter(%logspot(comI +8- !hat will %e output if you will execute following code; CincludeDstdio(hE char far 2 display+char far2-1 int main+-9 char far2 string.QcMuestion%an'(%logspot(comQ1 char far 2+2ptr-+char far 2-1 ptr.3display1 string.+2ptr-+string-1 printf+QHsQ)string-1 return 01 : char far 2display+char far 2 str-9 char far 2 temp.str1

temp.tempO,71 2temp.WR0W1 return str1 : Jutput* cMuestion%a' <xplanation* Here display is function whose parameter is pointer to character and return type is also pointer to character and ptr is its pointer( temp is char pointer temp.tempO,7 temp.YR0Y A%ove two lines replaces first dot character %y null character of string of varia%le string i(e( QcMuestion%an'R0%logspot(comQ As we 'now Hs print the character of stream up to null character(

Pointer to array of function in c


Array of function means array which content is address of function and pointer to array of function means pointer is pointing to such array( $n other word we can say pointer to array of functions is a pointer which is pointing to an array which contents are pointers to a function( <xamples of pointer to array of function* !hat will %e output if you will execute following code; CincludeDstdio(hE int display+-1 int+2array576-+-1 int+2+2ptr-576-+-1 int main+-9 array506.display1 array5,6.getch1 ptr.3array1

printf+QHdQ)+22ptr-+--1 +2+2ptrO,--+-1 return 01 : int display+-9 int x./1 return xOO1 : Jutput* / <xplanation* $n this example* array 56* $t is array of pointer to such function which parameter is void and return type is int data type( ptr* $t is pointer to array which contents are pointer to such function which parameter is void and return type is int type data( +22ptr-+- . +22 +3array-- +- FFptr.3array . +2array- +- FF from rule 23p.p .array 506 +- FFfrom rule 2+pOi-.p5i6 .display +- FFarray506.display +2+2ptrO,--+- .+2+23arrayO,--+- FFptr.3array .2+arrayO,- +- FF from rule 23p.p .array 5,6 +- FFfrom rule 2+pOi-.p5i6 .getch +- FFarray5,6.getch

Pointer to array of string in c programming Pointer to array of string* A pointer which pointing to an array which content is string) is 'nown as pointer to array of strings( !hat will %e output if you will execute following code; CincludeDstdio(hE

int main+-9 char 2array586.9QcQ)QcOOQ)Q&avaQ)QsMlQ:1 char 2+2ptr-586.3array1 printf+QHsQ)OO+2ptr-546-1 return 01 : Jutput* ava <xplanation* $n this example ptr* $t is pointer to array of string of siNe 8( array586* $t is an array and its content are string( Pictorial representation*

ote* $n the a%ove figure upper part of %ox represent content and lower part represent memory address( !e have assumed ar%itrary address( OO+2ptr-546 .OO+23array-546 FFptr.3array .OOarray546 .OOI&avaI

.IavaI FFSince ptr is character pointer so it FF will increment only one %yte ote* Hs is used to print stream of characters up to null +R0- character(

Pointer to structure in c programming


Pointer to structure* A pointer which is pointing to a structure is 'now as pointer to structure( <xamples of pointers to structure* !hat will %e output if you will execute following code; CincludeDstdio(hE struct address9 char 2name1 char street5,061 int pin1 :cus.9QA(ZumarQ)QHP4Q)8/>007:)2p.3cus1 int main+-9 printf+QHs HsQ)pPEname)+2p-(street-1 return 01 : Jutput* A(Zumar HP4 <xplanation* p is pointer to structure address( PE and +2-( Both are same thing( #hese operators are used to access data mem%er of structure %y using structureYs pointer(

Pointer to union in c programming


Pointer to structure* A pointer which is pointing to a structure is 'now as pointer to structure(

<xamples of pointers to structure* !hat will %e output if you will execute following code; CincludeDstdio(hE union address9 char 2name1 char street5,061 int pin1 :1 int main+-9 union address emp)2p1 emp(name.Q&aR0panQ1 p.3emp1 printf+QHs HsQ)pPEname)+2p-(name-1 return 01 : Jutput* &a &a <xplanation* p is pointer to union PE and +2-( Both are to access data mem%er Hs is used to print XR0Y

address( same thing( #hese operators are used of union %y using unionYs pointer( the string up to null character i(e(

Multilevel pointers in c programming


Multilevel pointers* A pointer is pointer to another pointer which can %e pointer to others pointers and so on is 'now as multilevel pointers( !e can have any level of pointers( <xamples of multilevel pointers in c*

+,- !hat will %e output if you will execute following code; CincludeDstdio(hE int main+-9 int s.4)2r.3s)22M.3r)222p.3M1 printf+QHdQ)p506506506-1 return 01 : Jutput* 4 <xplanation* As we 'now p5i6 .2+pOiSo) P506506506.2+p506506O0-.22p506.222p Another rule is* 23i.i So) 222p.222 +3M- .22M.22 +3r- .2r.2+3s- .s.4 +4- !hat will %e output if you will execute following code; CincludeDstdio(hE Cdefine int int2 int main+-9 int 2p)M1 p.+int 2-/1 M.,01 printf+QHdQ)MOp-1 return 01 : Jutput* 4/ <xplanation* $f you will see intermediate file you will find following code* CincludeDstdio(hE void main+-9 int 22p)M1

p.+int 22-/1 M.,01 printf+QHdQ)MOp-1 return 01 : <xplanations* Here M pointer and p is a num%er( $n c Address O num%er . Address So) ew address . which pointer . / O ,0 . /O,024 old address O num%er 2 SiNe of data type to is pointing( 2 siNeof +2int. 4/(

ote( !e are assuming default pointer is near( Actually it depends upon memory model(

Pointer to array of pointer to string in c programming


Pointer to array of pointer to string* A pointer to an array which contents are pointer to string( <xample of Pointer to array of pointer to string*

!hat will %e output if you will execute following code; CincludeDstdio(hE int main+-9 static char 2s576.9QmathQ)QphyQ)QcheQ:1 typedef char 2+ 2ppp-5761 static ppp p,.3s)p4.3s)p7.3s1 char 2 +2+2array576--576.93p,)3p4)3p7:1

char 2 +2+2+2ptr-576--576.3array1 p4O.,1 p7O.41 printf+QHsQ)+222ptr506-546-1 return 01 : Jutput* che <xplanation* Here ptr* is pointer to array of pointer to string( P,) p4) p7* are pointers to array of string( array576* is array which contain pointer to array of string( Pictorial representation*

ote* $n the a%ove figure upper part of %ox represent content and lower part represent memory address( !e have assumed ar%itrary address(

As we 'now p5i6.2+pOi+222ptr506-546.+2+222ptrO0--546.+222ptr-546 .+222+3array--546 FFptr.3array .+22array-546 FF"rom rule 23p.p .+22+3p,--546 FFarray.3p, .+2p,-546 .+23s-546 FFp,.3s .s546.IcheI
Pointer to three dimensional array in c programming

<xamples of pointers to 7 dimensional array* CincludeDstdio(hE int main+-9 const 576.90),)4)7)8)/)>)@)A)?),0),,),4:1 int const +2ptr-546576576.3array1 printf+QHdQ)2+2+2ptr-5,6O4--1 return 01 : Jutput* ,, <xplanation* $n this example* array 546576576*$t is three dimensional array and its content are constant integers( ptr* $t is pointer to such three dimensional array whose content are constant integer( array546576

Pictorial representation*

ote* $n the a%ove figure upper part of %ox represent content and lower part represent memory address( !e have assumed ar%itrary address(

2+2+2ptr- 5,6 O4.2+2+23array- 5,6 O4.2+2array 5,6 O4.2+array 5,6 506 O4.array 5,6 506 546 $(e( array element at the ,2+727- O0+7- O 4.,, th position starting from Nero which is ,,(
Pointer to two dimensional array in c programming <xamples of pointers to 4 dimensional array*

!hat will %e output if you will execute following code; CincludeDstdio(hE void main+-9

long array56576.9@l),8l)4,l)4Al)7/l)84l:1 long int +2ptr-546576.3array1 printf+QHliQ)P05,505ptr666-1 return 01 : Jutput* P4A <xplanation* P05,505ptr666 .P,505ptr66506 FF"rom rule array5i6.i5array6 .P05ptr65,6506 .Pptr 506 5,6 506 .P2ptr 506 5,6 FF"rom rule array5i6.2+arrayOi.P2+3array- 506 5,6 .P+3array- 506 5,6506 .P+23array-5,6506 FF"rom rule 23p.p .Parray5,6506 array5,6506 means ,2+7-O 0 . 7rd element of array starting from Nero i(e( 4A
sorting of array using pointer in c
int main+-9 int i)&)temp,)temp41 int arr5A6.9/)7)0)4),4),)77)4:1 int 2ptr1 for+i.01iD@1iOO-9 for+&.01&D@Pi1&OO-9 if+2+arrO&-E2+arrO&O,--9 ptr.arrO&1 temp,.2ptrOO1 temp4.2ptr1 2ptrPP.temp,1 2ptr.temp41 : : :

for+i.01iDA1iOOprintf+Q HdQ)arr5i6-1 : Jutput* 0 , 4 4 7 / ,4 77

Pointer to array of array in c

<xamples

of

pointer

to

array

of

array

in

c*

!hat will %e output if you will execute following code; CincludeDstdio(hE int main+-9 static float farray56 576.90(0f),(0f)4(0f)7(0f)8(0f)/(0f)>(0f)@(0f)A(0f:1 float +2array576576.93farray506)3farray5,6)3farray546:1 float +2+2ptr-56-576.3array1 printf+QHf Q)45+2+22ptrO,--6-1 return 01 : Jutput* /(000000 <xplanation* $n this example* farray 56576* $t is two dimension array and its content are float constants(

array 576*$t is one dimension array and its content are address of such one dimension array which content are float constant( ptr* $t is pointer to one dimension array which content are address of such one dimension array which content are float constant( Pictorial representation*

ote* $n the a%ove figure upper part of %ox represent content and lower part represent memory address( !e have assumed ar%itrary address(

45+2+22ptrO,--6 . +2+22ptrO,-- 546 . +2+223arrayO,-- 546 . +2+2arrayO,-- 546 . +2+array 506 O,-- 546 . +2+3farray 506 O,-- 546 .3farray 506 5,6 546 .23farray 5,6 546 .farray 5,6 546

$t is ,2+7- O4./th element of farray starting from Nero which is /(0f


Pointer to array of union in c programming
Pointer to array of union* A pointer to an array which contents is pointer to union is 'nown as pointer to array of union(

!hat will %e output if you will execute following code; union emp9 char 2name1 int id1 :1 int main+-9 static union emp e,.9QAQ:)e4.9QBQ:)e7.9QCQ:1 union emp+2array56-.93e,)3e4)3e7:1 union emp+2+2ptr-576-.3array1 printf+QHsQ)+2+2ptrO4--PEname-1 return 01 : Jutput* C <xplanation* $n this example* e,) e4) e7* #hey are varia%les of union emp( array 56*$t is one dimensional array of siNe thee and its content are address of union emp( ptr* $t is pointer to array of union( +2+2ptrO4--PEname

.+2+23arrayO4--PEname FFptr.3array .+2+arrayO4--PEname FFfrom rule 23p.p .array546PEname FFfrom rule 2+pOi-.p5i6 .+3e7-PEname FFarray546.3e7 .2+3e7-(name FFfrom rule PE. +2-( .e7(name FFfrom rule 23p.p .ICI
Pointer to array of structure in c programming
Pointer to array of structure* A pointer to an array which contents are pointer to structure is 'now pointer to array of structure(

!hat will %e output if you will execute following code; CincludeDstdio(hE struct emp9 char 2name1 int id1 :1 int main+-9 static struct emp e,.9QAQ),:)e4.9QBQ)4:)e7.9QCQ)7:1 struct emp+2array56-.93e,)3e4)3e7:1 struct emp+2+2ptr-576-.3array1 printf+QHs HdQ)+22+2ptrO,--(name)+2+2ptrO,--P Eid-1 return 01 : Jutput* B 4 <xplanation* +22+2ptrO,--(name

.+22+23arrayO,--(name FFptr.3array .+22+arrayO,--(name FFfrom rule 23p .p .+2array5,6-(name FFfrom rule 2+pOi-.p5i6 .+23e4-(name FFarray5,6.3e4 .e4(name.IBI FFfrom rule 23p .p +2+2ptrO,--PEid .+22+2ptrO,--(id FFfrom rule PE . +2-( .e4(id.4

Pointer to array of character in c


Pointer to array of character* A pointer to such an array which contents is character constants is 'nown as pointer to array of character constant(

!hat will %e output if you will execute following code; CincludeDstdio(hE char display+char +2-56-1 int main+-9 char c1 char character56.9>/)>>)>@)>A:1 char +2ptr-56.3character1 c.display+ptr-1 printf+QHcQ)c-1 return 01 : char display+char +2s-56-9 22sO.41 return 22s1 : Jutput* C

<xplanation* Here function display is passing pointer to array of characters and returning char data type( 22sO.4 .E22s.22sO4 .E22ptr.22ptrO4 FFs.ptr .E223character. 223characterO4 FFptr.3character .E2character.2characterO4 FFfrom rule 23p .p .Echaracter506.character506O4 FFfrom rule 2+pOi-.p5i6 .Echaracter 506 .>@ 22s.character 506 .>@ ote* ASC$$ value of XCY is >@

Pointer to array of integers* A pointer to such an array which contents are integer num%ers is 'nown as pointer to array of integer(
!hat will %e output if you will execute following code; CincludeDstdio(hE int main+-9 static int i)&)'1 int 2+2ptr-561 int 2array576.93i)3&)3':1 ptr.3array1 &.iOOO'O,01 OO+22ptr-1 printf+QHdQ)222ptr-1 return 01 :

Jutput* ,0 <xplanation* $n this example* array 56* $t is array of siNe three and its content are address of integer( ptr* $t is pointer address of integer( to array which content are

Pictorial representation a%ove declaration*

ote* $n the a%ove figure upper part of %ox represent content and lower part represent memory address( !e have assumed ar%itrary address(
&.iOOO'O,0 .iOO O 'O,0 .0 O0 O,0.,0 222ptr . 222 +3array- FFptr.3array . 22array FF"rom rule 23p.p

FF"rom rule array 506 .2+arrayO0- and OO +22ptr.2array 5,6 .23& .& .,0

!hat will %e output if you will execute following code; CincludeDstdio(hE int main+-9 int i)&)'1 int 2+2ptr-561 int 2array576.93i)3&)3':1 ptr.3array1 &.iOOO'O,01 OO+22ptr-1 printf+QHdQ)222ptr-1 return 01 : Jutput* Compiler error <xplanation* Address of mem%er of an array( auto varia%le cannot %e

Complex pointers in c programming

+,- Pointer to function +4- Pointer to array a( Pointer to array of integer %( Pointer to array of function c( Pointer to array of character d( Pointer to array of structure

e( Pointer f( Pointer g( Pointer h( Pointer i( Pointer &( Pointer +7- Pointer to +8- Pointer to +/- Multilevel

to array of union to array of array to two dimensional array to three dimensional array to array of string to array of pointer to string structure union pointers

Generic pointer in c programming

Generic pointer* void pointer in c is 'nown as generic pointer( [iteral meaning of generic pointer is a pointer which can point type of data( <xample* void 2ptr1 Here ptr is generic pointer( $mportant points a%out generic pointer in c; ,( !e cannot dereference generic pointer(

CincludeDstdio(hE Cinclude Dmalloc(hE int main+-9 void 2ptr1 printf+QHdQ)2ptr-1 return 01 : Jutput* Compiler error

4( !e can find the siNe of generic pointer using siNeof operator( Cinclude Dstring(hE CincludeDstdio(hE int main+-9 void 2ptr1 printf+QHdQ)siNeof+ptr--1 return 01 : Jutput* 4 <xplanation* SiNe of any type of near pointer in c is two %yte( 7( Generic pointer can hold any type of pointers li'e char pointer) struct pointer) array of pointer etc without any typecasting( <xample* CincludeDstdio(hE int main+-9 char c.WAW1 int i.81 void 2p1 char 2M.3c1 int 2r.3i1 p.M1 printf+QHcQ)2+char 2-p-1 p.r1 printf+QHdQ)2+int2-p-1 return 01 :

Jutput* A8 8( Any type of pointer can hold generic pointer without any typecasting( /( Generic pointers are used when we want to return such pointer which is applica%le to all types of pointers( "or example return type of malloc function is generic pointer %ecause it can dynamically allocate the memory space to stores integer) float) structure etc( hence we type cast its return type to appropriate pointer type( <xamples* ,( char 2c1 c.+char 2-malloc+siNeof+char--1 4( dou%le 2d1 d.+dou%le 2-malloc+siNeof+dou%le--1 7( Struct student9 char 2name1 int roll1 :1 Struct student 2stu1 Stu.+structstudent2-malloc+siNeof+struct student--1
NULL pointer in c programming

U[[ pointer* [iteral meaning of U[[ pointer is a pointer which is pointing to nothing( U[[ pointer points the %ase address of segment( <xamples of U[[ pointer*

,( int 2ptr.+char 2-01

4( 7( 8( /( >(

float 2ptr.+float 2-01 char 2ptr.+char 2-01 dou%le 2ptr.+dou%le 2-01 char 2ptr.YR0Y1 int 2ptr. U[[1 U[[;

!hat is meaning of

U[[ is macro constant which has %een defined in the heard file stdio(h) alloc(h) mem(h) stddef(h and stdli%(h as Cdefine U[[ 0 <xamples* !hat will %e output of following c program; Cinclude Dstdio(hE int main+-9 if+\ U[[printf+Q$ 'now preprocessorQ-1 else printf+Q$ donWt 'now preprocessorQ-1 : return 01

Jutput* $ 'now preprocessor <xplanation* \ U[[ . \0 . , $n if condition any non Nero num%er mean true( !hat will %e output of following c program; Cinclude Dstdio(hE int main+-9 int i1 static int count1 for+i. U[[1iD./1-9 countOO1

iO.41 : printf+QHdQ)count-1 return 01 : Jutput* 7 !hat will %e output of following c program; Cinclude Dstdio(hE int main+-9 Cifndef Cdefine Cendif U[[ U[[ /

printf+QHdQ) U[[OsiNeof+ U[[--1 return 01 : Jutput* 4 <xplanation* U[[OsiNeof+ U[[.0OsiNeoof+0.0O4 FFsiNe of int data type is two %yte( !e cannot copy any thing in the <xample* !hat will %e output of following c program; Cinclude Dstring(hE Cinclude Dstdio(hE int main+-9 U[[ pointer(

char 2str. U[[1 strcpy+str)QcPpointer(%logspot(comQ-1 printf+QHsQ)str-1 return 01 : Jutput* +nullWild pointer in c programming language.

!ild pointer* A pointer in c which has not %een initialiNed is 'nown as wild pointer( <xample* !hat will %e output of following c program;

CincludeDstdio(hE int main+-9 int 2ptr1 printf+QHuRnQ)ptr-1 printf+QHdQ)2ptr-1 return 01 : Jutput* Any address Gar%age value

Here ptr is wild pointer %ecause it has not %een initialiNed( #here is difference %etween the U[[ pointer and wild pointer( ull pointer points the %ase address of segment while wild pointer doesnYt point any specific memory location( 7( "ile pointer* #o 'now a%out "$[< pointer clic' here(
Dangling pointer problem in c programming

Different types of pointers* ,( Dangling pointer* $f any pointer is pointing the memory address of any varia%le %ut after some varia%le has deleted from that memory location while pointer is still pointing such memory location( Such pointer is 'nown as dangling pointer and this pro%lem is 'nown as dangling pointer pro%lem( $nitially*

[ater*

"or example* +M-!hat will %e output of following c program; CincludeDstdio(hE int 2call+-1 void main+-9 int 2ptr1 ptr.call+-1 fflush+stdin-1 printf+QHdQ)2ptr-1 : int 2 call+-9 int x.4/1 OOx1 return 3x1 : Jutput* Gar%age value ote* $n some compiler you may get warning message returning address of local varia%le or temporary <xplanation* varia%le x is local varia%le( $ts scope and lifetime is within the function call

hence after returning address of x varia%le x %ecame dead and pointer is still pointing ptr is still pointing to that location( Solution of this pro%lem* Ma'e the varia%le x is as static varia%le( $n other word we can say a pointer whose pointing o%&ect has %een deleted is called dangling pointer( CincludeDstdio(hE int 2call+-1 void main+-9 int 2ptr1 ptr.call+-1 fflush+stdin-1 printf+QHdQ)2ptr-1 : int 2 call+-9 static int x.4/1 OOx1 : return 3x1

Jutput* 4>
Near pointer in C programming

$n #UKBJ C there are three types of pointers( #UKBJ C wor's under DJS operating system which is %ased on A0A/ microprocessor( ,( ear pointer 4( "ar pointer

7( Huge pointer ear pointer* #he pointer which can points only >8ZB data segment or segment num%er A is 'nown as near pointer(

+$f you donYt 'now what is data segment the clic' here#hat is near pointer cannot access %eyond the data segment li'e graphics video memory) text video memory etc( SiNe of near pointer is two %yte( !ith help 'eyword near) we can ma'e any pointer as near pointer( <xamples* +,CincludeDstdio(hE

int main+-9 int x.4/1 int near2 ptr1 ptr.3x1 printf+GHdI)siNeof return 01 : Jutput* 4 +4CincludeDstdio(hE int main+-9 int near2 near 2 ptr1 printf+GHdI)siNeof+ptr-)siNeof+2ptr--1 return 01 : Jutput* 4 4 <xplanation* SiNe of any type of near pointer is two %yte( ear pointer only hold ,> %it offset address( Jffset address varies from 0000 to """" +in hexadecimal-( ote* $n printf statement to print address in hexadecimal) Hp is used( <xample* CincludeDstdio(hE the offset ptr-1

int main+-9 int i.,01 int 2ptr.3i1 printf+QHpQ)ptr-1 return 01 : Jutput* Jffset address in hexadecimal num%er format( Hp is also used to print any num%er in hexadecimal num%er format( <xample* CincludeDstdio(hE int main+-9 int a.,41 printf+QHpQ)a-1 return 01 : Jutput* 000C <xplanation* Hexadecimal value of ,4 is C( Consider the following two c program and analyNe its output* +,CincludeDstdio(hE int main+-9 int near 2 ptr.+ int 2-0S""""1

ptrOO1 ptrOO1 printf+GHpI)ptr-1 return 01 : Jutput* 0007 +4CincludeDstdio(hE int main+-9 int i1 char near 2ptr.+char 2-0x"""A1 for+i.01iD.,01iOO-9 printf+QHp RnQ)ptr-1 ptrOO1 : return 01 : Jutput* """A """B """C """D """< """" 0000 000, 0004 0007 0008

<xplanation* !hen we increment or decrement the offset address from maximum and minimum value respectively then it repeats the same value in cyclic order( #his property is 'nown as cyclic nature of offset address( Cyclic property of offset address( $f you increment the near pointer varia%le then move cloc'wise direction( $f you decrement the near pointer then move anti cloc'wise direction(

!hat is default type of pointer in C; Answer* $t depends upon memory model( !hat is memory model in C;
ar pointer in c programming

#he pointer which can point or access whole the residence memory of KAM i(e( which can access all ,> segments is 'nown as far pointer(

"ar pointer* +$f you donYt 'now what is segment the clic' hereSiNe of far pointer is 8 %yte or 74 %it( <xamples* +,- !hat will %e output of following c program; CincludeDstdio(hE int main+-9 int x.,01 int far 2ptr1 ptr.3x1 printf+QHdQ)siNeof ptr-1

return 01 : Jutput* 8 +4-!hat will %e output of following c program;

CincludeDstdio(hE int main+-9 int far 2near2ptr1 printf+QHd HdQ)siNeof+ptrreturn 01 : Jutput* 8 4 <xplanation* ptr is far pointer while 2ptr is near pointer( +7-!hat will %e output of following c program; )siNeof+2ptr--1

CincludeDstdio(hE int main+-9 int far 2p)far 2M1 printf+QHd HdQ)siNeof+preturn 01 : Jutput* 8 8 )siNeof+M--1

"irst ,> %it stores* Segment num%er

ext ,> %it stores* Jffset address

!hat is segment num%er and offset address; <xample* CincludeDstdio(hE int main+-9 int x.,001 int far 2ptr1 ptr.3x1 printf+QH"pQ)ptr-1 return 01 : Jutput* A"DA*"""8 Here A"DA is segment address and """8 is offset address in hexadecimal num%er format( ote* H"p is used for print offset and segment address of pointer in printf function in hexadecimal num%er format( $n the header file dos(h there are three macro functions to get the offset address and segment address from far pointer and vice versa( ,( "P]J""+-* #o get offset address from far address( 4( "P]S<G+-* #o get segment address from far address( 7( MZ]"P+-* #o ma'e far address from segment and offset address( <xamples* +,-!hat will %e output of following c program;

Cinclude Ddos(hE CincludeDstdio(hE int main+-9 int i.4/1 int far2ptr.3i1 printf+QHSHSQ)"P]S<G+ptr-)"P]J""+ptr--1 return 01 : Jutput* Any segment and offset address hexadecimal num%er format respectively( +4-!hat will %e output of following c program; Cinclude Ddos(hE CincludeDstdio(hE int main+-9 int i.4/1 int far2ptr.3i1 unsigned int s)o1 s."P]S<G+ptr-1 o."P]J""+ptr-1 printf+QH"pQ)MZ]"P+s)o--1 return 01 : Jutput* A"D?*"""8 +Assumeote* !e cannot guess what will %e offset address) segment address and far address of any far pointer (#hese address are decided %y operating system( [imitation of far pointer* in

!e cannot change or modify the segment address of given far address %y applying any arithmetic operation on it( #hat is %y using arithmetic operator we cannot &ump from one segment to other segment( $f you will increment the far address %eyond the maximum value of its offset address instead of incrementing segment address it will repeat its offset address in cyclic order( <xample* +M-!hat will %e output of following c program;

CincludeDstdio(hE int main+-9 int i1 char far 2ptr.+char 2-0xBA00"""A1 for+i.01iD.,01iOO-9 printf+QH"p RnQ)ptr-1 ptrOO1 : return 01 : Jutput* BA00*"""A BA00*"""B BA00*"""C BA00*"""D BA00*"""< BA00*"""" BA00*0000 BA00*000, BA00*0004 BA00*0007 BA00*0008

#his property of far pointer is called nature of far pointer within same segment( $mportant points a%out far pointer*

cyclic

,( "ar pointer compares %oth offset address and segment address with relational operators( <xamples* +,-!hat will %e output of following c program;

CincludeDstdio(hE int main+-9 int far 2p.+int 2-0S@04700001 int far 2M.+int 2-0SB04,00001 if+p..Mprintf+QBoth pointers are eMualQ-1 else printf+QBoth pointers are not

eMualQ-1

return 01 : Jutput* Both pointers are not eMual +4-!hat will %e output of following c program;

CincludeDstdio(hE int main+-9 int far 2p.+int 2-0S@04700001 int far 2M.+int 2-0SB04,00001 int near 2x)near2y1 x.+int near 2-p1

y.+int near 2-M1 if+x..yprintf+QBoth pointer are eMualQ-1 else printf+QBoth pointer are not eMualQ-1 : Jutput* Both pointers are eMual 4( "ar pointer doesnYt normaliNe( !hat is normaliNation of pointer;
!uge

return 01

Graphics "ideo memory

Graphics video memory in c using far pointer

+%-Graphics video memory* Segment num%er 0SA is 'nown as graphics video memory( #his segment has @40 columns and 800 rows( $ntersection of rows and columns is 'nown as pixel( SiNe of each pixel is one %yte which stores color information( <xample* +M-!hat will %e output of following c program; Cinclude Ddos(hE CincludeDstdio(hE int main+-9

int &1 union K<GS i)o1 char far 2ptr.+char 2-0SA00000001 i(h(ah.01 i(h(al.0x,71 intA>+0x,0)3i)3o-1 for+&.,1&D.,001&OO-9 2+ptrO&-.81 : return 01 : Jutput* Jne red color line in the graphics console as shown in the following figure

$n the a%ove program what is following codes; union K<GS i)o1 i(h(ah.01 i(h(al.0x,71 intA>+0x,0)3i)3o-1

Answer* #he tas' of this code is to switch the 4/> %it color graphics console window from default console window of #ur%o cOO $D<( More details clic' here( More examples* Copy the following code and execute the code in #ur%o c compile and see what is displaying( +,-!hat will %e output of following c program; Cinclude Ddos(hE CincludeDstdio(hE int main+-9 int &)'1 union K<GS i)o1 char far 2ptr.+char 2-0SA00000001 i(h(ah.01 i(h(al.0x,71 intA>+0x,0)3i)3o-1 for+'.01'D,001'OO-9 for+&.,1&D.7,?1&OO-9 2+ptrO&O'2740-.'1 : : return 01 :

+4-!hat will %e output of following c program;

Cinclude Ddos(hE CincludeDstdio(hE int main+-9 int &)'1 union K<GS i)o1 char far 2ptr.+char 2-0SA00000001 i(h(ah.01 i(h(al.0x,71 intA>+0x,0)3i)3o-1 for+'.01'D,001'OO-9 for+&.,1&D.7,?1&OO-9 2+ptrO&O'2740-.'1 : : return 01 :
Wor#ing with "ideo memory using far pointers

=<KL $ #<K<S#$ G #H$ G*


=ideo memory Segment num%er 0SA and 0SB is 'nown as memory( #here are two types of video memory( +a- #ext video memory +%- Graphics video memory +a- #ext video memory* Segment num%er 0SB is 'nown as text video memory( #his segment is divided into 4/ rows and A0 columns which creates A024/.4000 cells( SiNe of each cell is two %yte( <ach cell is divided into two parts each of siNe one %yte( video

+a#ext %yte* "irst %yte stores character information( $t stores character as ASC$$ code( +%Color %yte* Second %yte stores color information of text %yte character( $n other word we can say each even %yte stores character and each odd %yte stores color( Simple example* +M-!hat will %e output of following c program;

CincludeDstdio(hE int main+-9 int i1 char far 2ptr.+char 2-0SBA0000001 2ptr.WAW1 2+ptrO,-.81 return 01 : Jutput* $t will display character A color as shown following screen dump* in the red

Color scheme*

Color %yte of siNe A %it stores information in the following manner(

the

color

"irst four character( 0000 0000 0000 0000 000,* 00,0* 0,00* ,000*

%its

stores

color

information

of

Blue color +,Green color +4Ked color +8#o increase the intensity of color( +A-

ote* Any other num%er will generate mixture of a%ove four %asic colors( ext four %its stores color information of %ac'ground of character( 000, 0000* Blue color +,>00,0 0000* Green color +740,00 0000* Ked color +>8,000 0000* #o increase the +,4A-

intensity

of

color(

ote* Any other num%er will generate after mixing of a%ove four %asic colors( <xamples* +,-!hat will %e output of following c program;

CincludeDstdio(hE int main+-9 int i1 char far 2ptr.+char 2-0SBA0000001 2ptr.WAW1 2+ptrO,-.,1 2+ptrO4-.WBW1 2+ptrO7-.41 2+ptrO8-.WCW1 2+ptrO/-.81 return 01 : Jutput*

+4-!hat will %e output of following c program; CincludeDstdio(hE int main+-9

int i1 char far 2ptr.+char 2-0SBA0000001 2ptr.W!W1 2+ptrO,-.,1 2+ptrO4-.WJW1 2+ptrO7-.41 2+ptrO8-.WKW1 2+ptrO/-.81 2+ptrO>-.W[W1 2+ptrO@-.,1 2+ptrOA-.WDW1 2+ptrO?-.41 return 01 : Jutput*

+7-!hat

will

%e

output

of

following

program;

CincludeDstdio(hE FFMixture of %asic color int main+-9 int i1 char far 2ptr.+char 2-0SBA0000001 2ptr.W!W1 2+ptrO,-.71 2+ptrO4-.WJW1 2+ptrO7-./1 2+ptrO8-.WKW1 2+ptrO/-.>1 2+ptrO>-.W[W1 2+ptrO@-.@1 2+ptrOA-.WDW1 2+ptrO?-.71 return 01 : Jutput*

+8-!hat

will

%e

output

of

following

program;

CincludeDstdio(hE FF#o increase the intensity of color( int main+-9 int i1 char far 2ptr.+char 2-0SBA0000001 2ptr.WPW1 2+ptrO,-.,OA1 2+ptrO4-.WJW1 2+ptrO7-.4OA1 2+ptrO8-.W$W1 2+ptrO/-.7OA1 2+ptrO>-.W W1 2+ptrO@-.8OA1 2+ptrOA-.W#W1 2+ptrO?-./OA1 2+ptrO,0-.W<W1 2+ptrO,,-.>OA1 2+ptrO,4-.WKW1 2+ptrO,7-.@OA1 return 01 : Jutput*

+/-!hat will %e output of following c program; CincludeDstdio(hE FF for %ac'ground color int main+-9 int i1 char far 2ptr.+char 2-0SBA0000001 2ptr.WMW1 2+ptrO,-.8O741 2+ptrO4-.WAW1 2+ptrO7-.8O741 2+ptrO8-.W W1 2+ptrO/-.8O741 2+ptrO>-.W$W1 2+ptrO@-.8O,>1 2+ptrOA-.WSW1 2+ptrO?-.8O,>1 2+ptrO,0-.WHW1 2+ptrO,,-.8O,>1 return 01 :

Jutput*

Memory Model in C Programming

Memory model* $n c there are six type of memory model( $f you want to see all memory model in #ur%o COO $D< then open #ur%o COO $D< and the go* Jptions menu PE Compiler PE Code generation #hese memory models are* +a- #$ L +%- SMA[[ +c- M<D$UM +d- CJMPAC# +e- [AKG< +f- HUG< $f you want to change the memory model then go to* Jptions menu PE Compiler PE Code generation And select any memory model and clic' JZ %utton(

Properties of memory mode in C* +,- Memory model pointer in C( decides the default type of

ote* Code* A pointer to function is called code( Data* A pointer to varia%le is called data( <xamples* +,-!hat will %e output of following c program; void main+-9 int 2ptr1 printf+QHdQ)siNeof ptr-1 :

Jutput* Depends upon memory model( <xplanation* $f memory model is #$ L) SMA[[ or M<D$UM then default pointer will near and output will %e 4 other wise output will %e 8( +4-!hat will %e output of following c program; void main+-9 char +2fun-+-1 printf+QHdQ)siNeof fun-1 : Jutput* Depends upon memory model( <xplanation* fun is pointer to function( $f memory model is #$ L) SMA[[ or CJMPAC# then default pointer will near and output will %e 4 other wise output will %e 8( +7-!hat will %e output of following c program; void main+-9 int near 2p)2M1 printf+QHd ) HdQ)siNeof+p-)siNeof+M--1 : Jutput* 4) Depend upon memory model( <xplanation* p is near pointer while type pointer M will depend what is default type pointer( +8-!hat will %e output of following c program; void main+-9 char huge 22p1 printf+QHd ) HdQ)siNeof+p-)siNeof+2p--1 : of of

Jutput* 8) Depend upon memory model( <xplanation* p is huge pointer while type pointer 2p will depend what is default type pointer( of of

+/-!rite a c program to find the memory model of you computer; void main+-9 Cif defined ]]#$ L]] printf+QMemory model is* #$ LQ-1 Celif defined ]]SMA[[]] printf+QMemory model is*SMA[[ Q-1 Celif defined ]]M<D$UM]] printf+QMemory model is*M<D$UM Q-1 Celif defined ]]CJMPAC#]] printf+QMemory model is*CJMPAC# Q-1 Celif defined ]][AKG<]] printf+QMemory model is*[AKG< Q-1 Celif defined ]]HUG<]] printf+QMemory model is*HUG< Q-1 Cendif : +4- Memory segment( models decide the default siNe of

Memory Organization for a process -------------------------------------------CODE SEGMEN ! contains e"ecuta#le code D$ $SEGMEN !contains static and glo#al varia#le %E$P SEGMEN !Dynamically allocated varia#les &ill #e in heap S $C' SEGMEN !(or local or automatic varia#les

!ow $any %ype of Constant in C

What is constant& !ow many type of constant in C& 'ns(

Constant is fixed "alue which can not be changed by the program during the execution. Constants are classified as We can ma#e any identifier constant by const #eyword( e.g

const int total)*+ now total is constant.We cannot change the "alue of total. define directi"e ( e.g ,define fraction -.* Preprocessor are processed before the actual compilation. .o it paste will paste the -.* in place of fraction in the program before actual compilation. enum #eyword ( e.g enum si/e 0 a)12b)32c2d2e4+ now a2b2c2d and e are constant we cannot change the "alue of a by program.

Cyclic Nature of a Data type


what is meaning of cyclic nature of the data type & 'ns( 5n the data type char 2int2long int if we assign the "alue beyond range of of data type instead of gi"ing compiler error it repeat the same "alue in cyclic order. unsigned char ( 6ange of unsigned char is 7 to 8** .

5f we will assign a "alue greater than 8** then "alue of "ariable will be changed to a "alue if we will mo"e cloc#wise direction as shown in the figure according to number.5f number is less than 7 then mo"e anti cloc#wise direction. 5f number is 9 where 9 is greater than 8** then

New "alue ) 9 : 8*; 5f number is < where < is less than 7 then New "alue ) 8*; = > <: 8*; ? signed char ( 6ange of unsigned char is @-81 to -83 .

5f we will assign a "alue greater than -83 then "alue of "ariable will be changed to a "alue if we will mo"e cloc#wise direction as shown in the figure according to number. 5f number is less than @-81 then mo"e anti cloc#wise direction. 5f number is 9 where 9 is greater than -83 then p ) 9 : 8*; if p A)-83 new "alue ) p else new "alue ) p @ 8*; 5f number is < where < is less than @-81 then p ) < : 8*; 5f p A) -83 New "alue ) @p else New "alue ) 8*; @p unsigned int ( 6ange of unsigned int is 7 to ;*B*B* .

5f we will assign a "alue greater than ;**B* then "alue of "ariable will be changed to a "alue if we will mo"e cloc#wise direction as shown in the figure according to number.5f number is less than 7 then mo"e anti cloc#wise direction. 5f number is 9 where 9 is greater than ;**B* then New "alue ) 9 : ;**B;

5f number is < where < is less than 7 then New "alue ) ;**B;= > <: ;**B;? signed int ( 6ange of unsigned int is @B83;1 to B83;3 .

5f we will assign a "alue greater than B83;3 then "alue of "ariable will be changed to a "alue if we will mo"e cloc#wise direction as shown in the figure according to number. 5f number is less than @B83;1 then mo"e anti cloc#wise direction. 5f number is 9 where 9 is greater than B83;3 then p ) 9 : ;**B; if p A)B83;3 new "alue ) p else new "alue ) p @ ;**B; 5f number is < where < is less than @B83;1 then p ) < : ;**B; 5f p A) B83;3 New "alue ) @p else New "alue ) ;**B; @p .ame thing is occurred in case of signed long int and unsigned long int

$emory $ap of loat and Double


!ow float2double data type is represented in the memory & 'ns( float ( 5t is B8 bit data type. 8B bit ( for mantissa 1 bit ( for exponent > including one signed bit of exponent ? - bit ( for signed bit of mantissa

e.g $emory representation of float a ) @B.Bf+ step- ( con"ert the number >B.B? into binary form binary "alue of B.B is --.7-77--77--77--77--77--77--77--77--C step8 ( con"ert the binary number in the scientific form --.7-77--77--77--77--77--77--77--77--C ) -.-7-77--77--77--77--77--77--77--77--CD-7E-

.tepF ( find exponent and mantissa and signed bit $antissa ) .-7-77-- 77--77-- 77--77--7 >only first 8B bit ? Gxponent) .igned bit )- > .ince a is negati"e number ? .tep* ( store - in the signed bit >green colour in the figure ? .tep ;( 'dd -83 in the exponent and con"ert in the binary number form > since in 3 bit of exponent except signed bit maximum possible number is ------- ? Gxponent) -83H-)-81 Iinary form of -81 is -777777 7 .tore first bit i.e 7 at the 7 th position of exponent. >in figure red colour /ero? .tore rest 3 bit at - to 3 bit of exponent from right to left >in figure red color to 3? .tep 3( store the 8B bit mantissa at - to 8B bit position in as shown in figure ..tore -st bit of mantissa >from right to left ? i.e - at the position - of mantissa as in figure 28nd bit of mantissa i.e 7 at the position 8 of mantissa as in figure and so on. 5n the memory @B.B is represent as (

double( 5t is ;F bit data type. *8 bit ( for mantissa -- bit ( for exponent >including one signed bit of exponent ? - bit ( for signed bit of mantissa e.g $emory representation of double a ) @B.B + step- ( con"ert the number >B.B? into binary form binary "alue of B.B is --.7-77--77--77--77--77--77--77--77--C step8 ( con"ert the binary number in the scientific form --.7-77--77--77--77--77--77--77--77--C ) -.-7-77--77--77--77--77--77--77--77--CD-7E.tepF ( find exponent and mantissa and signed bit $antissa ) .-7-7 7--77--7 7--77--7 7--77--7 7--77--7 7--77--7 7--77--7 >only first *8 bit ? Gxponent) .igned bit )- > .ince a is negati"e number ? .tep* ( store - in the signed bit >green colour in the figure ? .tep ;( 'dd -78B in the exponent and con"ert in the binary number form > since in -7 bit of exponent except signed bit maximum possible number is ---------- ? Gxponent) -78BH-)-78F Iinary form of -78F is -7777777777 .tore first F bit i.e 7777 at the 7 to B position of exponent. >in figure blue colour digit? .tore rest 3 bit at F to -7 bit of exponent from right to left >in figure blue color F to -7?

.tep 3( store the *8 bit mantissa at - to *8 bit position in as shown in figure ..tore -st bit of mantissa >from right to left ? i.e - at the position - of mantissa as in figure 28nd bit of mantissa i.e 7 at the position 8 of mantissa as in figure and so on. 5n the memory @B.B is represented as (

$emory $ap of a 5nteger


!ow int data type is represented in the memory& 'ns( int may be signed or unsigned both has different memory representation. -. $emory representation of( unsigned int a)3+ 5t is -;@bit data type and all -; bit is data bit. Iinary eJui"alent of 3 is --or -; bit we will add -B /ero in the left side i.e 77777777 77777--.ince %urbo C is based on 171* microprocessor which follow little@endian. !ere ' is 77777--- and I is 77777777 $emory representation (

Note( same memory representation will be of ( unsigned short int a)3+ 8. $emory representation of( unsigned long int a)11111*****+ 5t is B8@bit data type and all B8 bit is data bit. Iinary eJui"alent of 11111**** is --7-77 -----7-- 7-7-777- 77--77-or B8 bit we will add 8 /ero in the left side i.e 77--7-77 -----7-- 7-7-77777--77-!ere ' is 77--7-77 I is -----7-C is 7-7-777D is 77--77-$emory representation (

B. >a? $emory representation of( int a)3 or signed int a)3+ 5t is -; bit data type . -* bit( data bit - bit( signed bit

Iinary eJui"alent of 3 is --or -; bit we will add -B /ero in the left side i.e 77777777 77777--!ere ' is 77777--I is 77777777 $emory representation (

Note( same memory representation will be of( short int a)3 or signed short int a)3+ >b? $emory representation of ( int a) @3 or signed int a) @3+ 5t is -; bit data type . Iinary eJui"alent of 3 is --or -; bit we will add -B /ero in the left side i.e 77777777 77777--.ince a is negati"e number so it will first con"ert in the 8Ks complement format before stored in the memory.

$emory representation ( Note( same memory representation will be of ( short int a)@3 or signed short int a)@3+ >F? >a? $emory representation of ( long int a)11111***** or signed long int a)11111*****+ 5t is B8 bit data type . B- bit ( data bit - bit ( signed bit Iinary eJui"alent of 11111***** is --7-77 -----7-- 7-7-777- 77--77-or -; bit we will add 8 /ero in the left side i.e 77--7-77 -----7-- 7-7-77777--77-!ere ' is 77--77-I is 7-7-777C is -----7-D is 77--7-77 $emory representation (

>b? $emory representation of ( long int a) @11111***** or signed long int a) @11111*****+ 5t is B8 bit data type . Iit no B- is signed bit. Iinary eJui"alent of 11111***** is --7-77 -----7-- 7-7-777- 77--77-or B8 bit we will add 8 /ero in the left side i.e 77--7-77 -----7-- 7-7-77777--77-.ince a is negati"e number so it will first con"ert in the 8Ks complement format before stored in the memory.

$emory representation (

What is endianness of processor &


What is endianness of processor& 'ns( 5f the si/e of data type is more than one byte then endianness decides the memory representation of data type.%here are two type of endianness. Little@endian( %he processor which follow the following memory representation of data is #nown as little@endian processor.

irst ' will fill then I then C then D then G and so on from right to left. Gxample of processor( 171*2171;2171121781;217B1;2p-2p8 etc. Iig@endian( %he processor which follow the following memory representation of data is #nown as big@endian processor.

irst ' will fill then I then C then D then G from right to left. Gxample of processor( $otorola2 5I$ PC etc.

'd"ance C Programming
System level programming %y c programming language(

$n the header file dos(h there are two important structures and union +Kemem%er this structure,( struct BL#<K<GS 9 unsigned char al) ah) %l) %h1 unsigned char cl) ch) dl) dh1 :1 4( struct !JKDK<GS 9 unsigned int ax) %x) cx) dx1 unsigned int si) di) cflag) flags1 :1 7( union K<GS 9 struct !JKDK<GS x1 struct BL#<K<GS h1 :1 #here is function intA>+- which has %een defined in dos(h header file( $t is general A0A> software interrupt interface( $t will %etter to explain it %y an example( !rite a c program to display mouse pointer; Answer* void main+9 union K<GS i)o1 i(x(ax.,1 intA>+0x77)3i)3o-1 getch+-1 : <xplanation* #o write such program interrupt ta%le is necessary(

Complete interrupt table $t is a small part of interrupt ta%le( $t has four field input) output) service num%er and purpose) now see the first line which is inside the rectangle( #o display the mouse pointer assign ax eMual to , i(e( service num%er while ax is define in the !JKDK<GS struct !JKDK<GS 9 unsigned int ax) %x) cx) dx1 unsigned int si) di) cflag) flags1 :1 and !JKDKGS is define in the union K<GS union K<GS 9 struct !JKDK<GS x1 struct BL#<K<GS h1 :1 So to access the ax first declare a varia%le of K<GS i(e( K<GS i)o1 #o access the ax write i(x(ax +!e are using structure varia%le i %ecause ax is input) see interrupt ta%leSo to display mouse pointer assign the value of service num%er* i(x(ax.,1 #o give the this information to microprocessor !e use intA> function( $t has three parameters ,( $nterrupt num%er i(e( 0x77 4( union K<GS 2inputregiste i(e( 3i 7( union K<GS 2outputregiste i(e( 3o1 So &rite! intA> +0x77) 3i) 3o-1

List Lf 5nterrupts
Print Screen
5nterrupt 6eturns Notes 7x* Nothing .end screen contents to printer. Wor#s in text mode.

Get Peripheral Equipment List


5nterrupt 5nput 6eturns Notes 7x-Nothing '9 ) eJuipment list Iit setting for '9 are as follows( 77 ) dis# dri"e presentMabsent >7(absent2 -(present? 7- ) math co@processor >7(absent2 -(present? 78@7B ) 6'$ in -; #b bloc#s 7F@7* ) initial "ideo mode 77 ) >unused? 7- ) F7 x 8* colour -7 ) 17 x 8* colour -- ) 17 x 8* mono 7;@73 ) number of dis# dri"es 71 ) D$' present >7(present2 -(absent ? 7N@-- ) number of serial ports -8 ) game port >7(absent2 -(present? -B ) serial printer -F@-* ) number of printers

Reset Disk Controller


5nterrupt 5nput 7x-B '! ) 7x7 DL ) dri"e 7x77@7x3 floppy dis# 7x17@7x fixed dis# Nothing

6eturns

Get Disk Status


5nterrupt 5nput 7x-B '! ) 7x7DL ) dri"e 7x77@7x3 floppy dis# 7x17@7x fixed dis# 'L ) status code

6eturns

C inter"iew Juestions and answers

5nter"iew Juestions and answer of C with explanation for fresher


-. Write a c program to print !ello world without using any semicolon.
Gxplanation(

.olution( "oid main>?0 if>printf>O!ello worldO??0 4 4 .olution( 8 "oid main>?0 while>Pprintf>O!ello worldO??0 4 4 .olution( B "oid main>?0 switch>printf>O!ello worldO??0 4

4 8. .wap two "ariables without using third "ariable.


Gxplanation(

,includeAstdio.hQ int main>?0 int a)*2b)-7+ MMprocess one a)bHa+ b)a@b+ a)a@b+ printf>Oa) :d b) :dO2a2b?+ MMprocess two a)*+ b)-7+ a)aHb@>b)a?+ printf>ORna) :d b) :dO2a2b?+ MMprocess three a)*+ b)-7+ a)aEb+ b)aEb+ a)bEa+

printf>ORna) :d b) :dO2a2b?+

MMprocess four a)*+ b)-7+ a)b@Sa@-+ b)aHSbH-+ a)aHSbH-+ printf>ORna) :d b) :dO2a2b?+

MMprocess fi"e a)*2 b)-7+ a)bHa2b)a@b2a)a@b+ printf>ORna) :d b) :dO2a2b?+ return 7+ 4 B. What is dangling pointer in c&
Gxplanation(

Dangling pointer( 5f any pointer is pointing the memory address of any "ariable but after some "ariable has deleted from that memory location while pointer is still pointing such

memory location. .uch pointer is #nown as dangling pointer and this problem is #nown as dangling pointer problem. 5nitially(

Later(

or example( What will be output of following c program& ,includeAstdio.hQ int Dcall>?+ int main>?0 int Dptr+

ptr)call>?+ fflush>stdin?+ printf>O:dO2Dptr?+ return 7+ 4 int D call>?0 int x)8*+ HHx+ return Tx+ 4 Lutput( Garbage "alue Note( 5n some compiler you may get warning message returning address of local "ariable or temporary Gxplanation( "ariable x is local "ariable. 5ts scope and lifetime is within the function call hence after returning address of x "ariable x became dead and pointer is still pointing ptr is still pointing to that location. .olution of this problem( $a#e the "ariable x is as static "ariable. 5n other word we can
say a pointer whose pointing obUect has been deleted is called dangling pointer.

,includeAstdio.hQ int Dcall>?+ int main>?0

int Dptr+ ptr)call>?+ fflush>stdin?+ printf>O:dO2Dptr?+ return 7+ 4 int D call>?0 static int x)8*+ HHx+ return Tx+ 4 Lutput( 8; F. What is wild pointer in c&
Gxplanation(

' pointer in c which has not been initiali/ed is #nown as wild pointer. Gxample( What will be output of following c program& int main>?0 int Dptr+ printf>O:uRnO2ptr?+ printf>O:dO2Dptr?+

return 7+ 4 Lutput( 'ny address Garbage "alue !ere ptr is wild pointer because it has not been initiali/ed. %here is difference between the NULL pointer and wild pointer. Null pointer points the base address of segment while wild pointer doesnKt point any specific memory location. *. What are merits and demerits of array in c&
Gxplanation(

$erits( >a? We can easily access each element of array. >b? Not necessity to declare too many "ariables. >c? 'rray elements are stored in continuous memory location. Demerit( >a? Wastage of memory space. We cannot change si/e of array at the run time. >b? 5t can store only similar type of data. ;. Do you #now memory representation of int a ) 3 &
Gxplanation(

$emory representation of( signed int a)3+ >5n %urbo c compiler?

signed short int a)3 >Ioth turbo c and Linux gcc compiler? Iinary eJui"alent of data 3 in -; bit( 77777777 77777--Data bit( 7777777 77777--- >%a#e first -* bit form right side? .ign bit( 7 >%a#e leftmost one bit? irst eight bit of data bit from right side i.e. 77777--- will store in the leftmost byte from right to left side and rest se"en bit of data bit i.e. 7777777 will store in rightmost byte from right to left side as shown in the following figure(

3. What is and why array in c&


Gxplanation(

'n array is deri"ed data type in c programming language which can store similar type of data in continuous memory location. Data may be primiti"e type >int2 char2 float2 doubleC?2 address of union2 structure2 pointer2 function or another array. Gxample of array declaration( int arrV*W+ char arrV*W+ float arrV*W+ long double arrV*W+ char D arrV*W+

int >arrVW?>?+ double DD arrV*W+ 'rray is useful when( >a? We ha"e to store large number of data of similar type. 5f we ha"e large number of similar #ind of "ariable then it is "ery difficult to remember name of all "ariables and write the program. or example( MMP6LCG.. LNG int main>?0 int ax)-+ int b)8+ int cg)*+ int dff)3+ int am)1+ int raUa)7+ int rani)--+ int xxx)*+ int yyy)N7+ int p+ int J+ int r+ int a"g+ a"g)>axHbHcgHdffHamHraUaHraniHxxxHyyyHpHJHr?M-8+

printf>O:dO2a"g?+ return 7+ 4 5f we will use array then abo"e program can be written as( MMP6LCG.. %WL int main>?0 int arrVW)0-282*2321272--2*2*74+ int i2a"g+ for>int i)7+iA-8+iHH?0 a"g)a"gHarrViW+ 4 printf>O:dO2a"gM-8?+ return 7+ 4 Xuestion( Write a C program to find out a"erage of 877 integer number using process one and two. >b? We want to store large number of data in continuous memory location. 'rray always stores data in continuous memory location. What will be output when you will execute the following program& int main>?0 int arrVW)072-72872B72F74+

char Dptr)arr+ arr)arrH8+ printf>O:dO2Darr?+ return 7+ 4 'd"antage of using array( -. 'n array pro"ides singe name ..o it easy to remember the name of all element of an array. 8. 'rray name gi"es base address of an array ..o with the help increment operator we can "isit one by one all the element of an array. B. 'rray has many application data structure. 'rray of pointers in c( 'rray whose content is address of another "ariable is #nown as array pointers. or example( int main>?0 float a)7.7f2b)-.7f2c)8.7f+ float D arrVW)0Ta2Tb2Tc4+ b)aHc+ printf>O:fO2arrV-W?+ return 7+ 4 1. Why we use do@while loop in c& 'lso tell any properties which you #now&

Gxplanation(

5t is also called as post tested loop. 5t is used when it is necessary to execute the loop at least one time. .yntax( do 0 Loop body 4 while >Gxpression?+ Gxample( int main>?0 int num2i)7+

do0 printf>O%o enter press -RnO?+ printf>O%o exit press 8O?+ scanf>O:dO2Tnum?+ HHi+ switch>num?0 case -(printf>O<ou are welcomeRnO?+brea#+ default ( exit>7?+ 4 4 while>iA)-7?+ return 7+

4 Lutput( B B F F 5f there is only one statement in the loop body then braces is optional. or example( >a? int main>?0 double i)*.*;31+ do printf>OhiO?+ while>Pi?+ return 7+ 4 Lutput( B B F F >b? int main>?0 double i)*.;BBBB+ do printf>OhiO?+ while>Pi?+ return 7+ 4 Lutput( hi

>c? int main>?0 int x)8*2y)-+ do if>xQ*? printf>O LNGO?+ else if>xQ-7? printf>O %WLO?+ else if>x))8*? printf>O %!6GGO?+ else printf>O LU6O?+ while>y@@?+ return 7+ 4 Lutput( LNG LNG N. What is the meaning of prototype of a function&
Gxplanation(

Prototype of a function Declaration of function is #nown as prototype of a function. Prototype of a function means >-? What is return type of function&

>8? What parameters are we passing& >B? or example prototype of printf function is( int printf>const char D2 C?+ 5.e. its return type is int data type2 its first parameter constant character pointer and second parameter is ellipsis i.e. "ariable number of arguments. -7. c& Write a c program to modify the constant "ariable in

Gxplanation(

<ou can modify constant "ariable with the help of pointers. or example( ,includeAstdio.hQ int main>?0 int i)-7+ int Dptr)Ti+ Dptr)>int D?87+ printf>O:dO2i?+ return 7+ 4 Lutput( 87 --. What is pointer to a function&

Gxplanation(

>-? What will be output if you will execute following code& int D function>?+

int main>?0 auto int Dx+ int D>Dptr?>?+ ptr)Tfunction+ x)>Dptr?>?+ printf>O:dO2Dx?+ 4 int Dfunction>?0 static int a)-7+ return Ta+ 4 Lutput( -7 Gxplanation( !ere function is function whose parameter is "oid data type and return type is pointer to int data type. x)>Dptr?>? )Q x)>DTfunctyion?>? MMptr)Tfunction )Q x)function>? MM rom rule DTp)p )Q x)Ta .o2 Dx ) DTa ) a )-7 >8? What will be output if you will execute following code& int find>char?+ int>Dfunction>??>char?+

int main>?0 int x+ int>Dptr?>char?+ ptr)function>?+ x)>Dptr?>Y'Y?+ printf>O:dO2x?+ return 7+ 4 int find>char c?0 return c+ 4 int>Dfunction>??>char?0 return find+ 4 Lutput( ;* Gxplanation( !ere function whose name is function which passing "oid data type and returning another function whose parameter is char data type and return type is int data type. x)>Dptr?>Z'K? )Q x) >Dfunction >?? >Z'K? MMptr)function >? MMTfind)function >? i.e. return type of function >? )Q x) >D Tfind? >Z'K?

)Q x) find >Z'K? MM rom ruleDTp)p )Q x) ;* >B? What will be output if you will execute following code& char D call>int D2float D?+ int main>?0 char Dstring+ int a)8+ float b)8.7l+ char D>Dptr?>intD2float D?+ ptr)Tcall+ string)>Dptr?>Ta2Tb?+ printf>O:sO2string?+ return 7+ 4 char Dcall>int Di2float DU?0 static char Dstr)Octechnotips.blogspot.comO+ str)strHDiH>int?>DU?+ return str+ 4 Lutput( inter.blogspot.com Gxplanation( !ere call is function whose return type is pointer to character and one parameter is pointer to int

data type and second parameter is pointer to float data type and ptr is pointer to such function. str) strHDiH >int? >DU? )[ctechnotips.blogspot.com[ H DTaH >int? >DTb? MMi)Ta2 U)Tb )[ctechnotips.blogspot.com[ H aH >int? >b? )[ctechnotips.blogspot.com[ H8 H >int? >8.7? )[ctechnotips.blogspot.com[ HF )[hnotips.blogspot.com[ >F? What will be output if you will execute following code& char far D display>char farD?+ int main>?0 char farD string)Octechnotips.blogspot.comO+ char far D>Dptr?>char far D?+ ptr)Tdisplay+ string)>Dptr?>string?+ printf>O:sO2string?+ 4 char far Ddisplay>char far D str?0 char far D temp)str+ temp)tempH--+ Dtemp)YR7Y+

return str+ 4 Lutput( ctechnotips Gxplanation( !ere display is function whose parameter is pointer to character and return type is also pointer to character and ptr is its pointer. temp is char pointer temp)tempH-temp)KR7K 'bo"e two lines replaces first dot character by null character of string of "ariable string i.e. OctechnotipsR7blogspot.comO 's we #now :s print the character of stream up to null character. -8. Write a c program to find si/e of structure without using si/eof operator&
Gxplanation(

struct 'IC0 int a+ float b+ char c+ 4+ int main>?0 struct 'IC Dptr)>struct 'IC D?7+

ptrHH+ printf>O.i/e of structure is( :dO2Dptr?+ return 7+ 4 -B. What is NULL pointer&

Gxplanation(

Literal meaning of NULL pointer is a pointer which is pointing to nothing. NULL pointer points the base address of segment. Gxamples of NULL pointer( -. int Dptr)>char D?7+ 8. float Dptr)>float D?7+ B. char Dptr)>char D?7+ F. double Dptr)>double D?7+ *. char Dptr)KR7K+ ;. int Dptr)NULL+ What is meaning of NULL& 'nswer( NULL is macro constant which has been defined in the heard file stdio.h2 alloc.h2 mem.h2 stddef.h and stdlib.h as ,define NULL 7 Gxamples( >-?What will be output of following c program&

,include Ostdio.hO int main>?0 if>PNULL? printf>O5 #now preprocessorO?+ else printf>O5 donYt #now preprocessorO?+ 4 Lutput( 5 #now preprocessor Gxplanation( PNULL ) P7 ) 5n if condition any non /ero number mean true. >8?What will be output of following c program& ,include Ostdio.hO int main>?0 int i+ static int count+ for>i)NULL+iA)*+?0 countHH+ iH)8+ 4 printf>O:dO2count?+

4 Lutput( B >B?What will be output of following c program& ,include Ostdio.hO int main>?0 ,ifndef NULL ,define NULL * ,endif printf>O:dO2NULLHsi/eof>NULL??+ 4 Lutput( 8 Gxplanation( NULL H si/eof>NULL? )7 H si/eoof>7? )7H8 MMsi/e of int data type is two byte. We cannot copy anything in the NULL pointer. Gxample( >F?What will be output of following c program& ,include Ostring.hO int main>?0 char Dstr)NULL+

strcpy>str2Octechnotips.blogspot.comO?+ printf>O:sO2str?+ return 7+ 4 Lutput( >null? null pointer assignment -F. What is difference between pass by "alue and pass by reference&
Gxplanation(

5n c we can pass the parameters in a function in two different ways. >a?Pass by "alue( 5n this approach we pass copy of actual "ariables in function as a parameter. !ence any modification on parameters inside the function will not reflect in the actual "ariable. or example( ,includeAstdio.hQ int main>?0 int a)*2b)-7+ swap>a2b?+ printf>O:d :dO2a2b?+ return 7+ 4 "oid swap>int a2int b?0 int temp+ temp )a+

a)b+ b)temp+ 4 Lutput( * -7

>b?Pass by reference( 5n this approach we pass memory address actual "ariables in function as a parameter. !ence any modification on parameters inside the function will reflect in the actual "ariable. or example( ,incudeAstdio.hQ int main>?0 int a)*2b)-7+ swap>Ta2Tb?+ printf>O:d :dO2a2b?+ return 7+ 4 "oid swap>int Da2int Db?0 int Dtemp+ Dtemp )Da+ Da)Db+ Db)Dtemp+ 4 Lutput( -7 * -*. What is si/e of "oid pointer&

Gxplanation(

.i/e of any type of pointer in c is independent of data type which is pointer is pointing i.e. si/e of all type of pointer >near? in c is two byte either it is char pointer2 double pointer2 function pointer or null pointer. \oid pointer is not exception of this rule and si/e of "oid pointer is also two byte. -;. What is difference between uninitiali/ed pointer and null pointer&
Gxplanation(

'n uninitiali/ed pointer is a pointer which points un#nown memory location while null pointer is pointer which points a null "alue or base address of segment. or example( int Dp+ MMUninitiali/ed pointer int DJ) >int D?7+ MMNull pointer ,includeAstdio.hQ int Dr)NULL+ MMNull pointer What will be output of following c program& ,includeAstring.hQ ,includeAstdio.hQ int main>?0 char Dp+ MMUninitiali/ed pointer char DJ)NULL+ MMNull pointer+ strcpy>p2OctechnotipsO?+ strcpy>J2OctechnotipsO?+

printf>O:s :sO2p2J?+ return 7+ 4 Lutput( ctechnotips >null?Null pointer assignment -3. Can you read complex pointer declaration&

Gxplanation(

6ule -. 'ssign the priority to the pointer declaration considering precedence and associati"e according to following table.

>?( %his operator beha"es as brac#et operator or function operator. VW( %his operator beha"es as array subscription operator. D( %his operator beha"es as pointer operator not as multiplication operator.

5dentifier( 5t is not an operator but it is name of pointer "ariable. <ou will always find the first priority will be assigned to the name of pointer. Data type( 5t is also not an operator. Data types also includes modifier >li#e signed int2 long double etc.? <ou will understand it better by examples( >-? !ow to read following pointer& char >D ptr?VBW 'nswer( .tep -( >? and VW enUoys eJual precedence. .o rule of associati"e will decide the priority. 5ts associati"e is left to right so first priority goes to >?.

.tep 8( 5nside the brac#et D and ptr enUoy eJual precedence. rom rule of associati"e >right to left? first priority goes to ptr and second priority goes to D.

.tepB( 'ssign third priority to VW.

.tepF( .ince data type enUoys least priority so assign fourth priority to char.

Now read it following manner( ptr is pointer to such one dimensional array of si/e three which content char type data. >8? !ow to read following pointer& float >D ptr?>int? 'nswer(
'ssign the priority considering precedence and associati"e.

Now read it following manner(

ptr is pointer to such function whose parameter is int type data and return type is float type data. 6ule 8( 'ssign the priority of each function parameter separately and read it also separately. Understand it through following example. >B? !ow to read following pointer& "oid >Dptr?>int >D?V8W2int >D? "oid?? 'nswer(
'ssign the priority considering rule of precedence and associati"e.

Now read it following manner( ptr is pointer to such function which first parameter ispointer to one dimensional array of si/e two which contentint type data and second parameter is pointer to such function which parameter is "oid and return type is intdata type and return type is "oid. >F? !ow to read following pointer& int > D > D ptr ? V * W ? > ? 'nswer(
'ssign the priority considering rule of precedence and associati"e.

Now read it following manner( ptr is pointer to such array of si/e fi"e which content are pointer to such function which parameter is "oid and return type is int type data. >*? !ow to read following pointer& doubleD>D>Dptr?>int??>double DD2char c?
'nswer(

'ssign the priority considering rule of precedence and associati"e.

Now read it following manner( ptr is pointer to function which parameter is int type data and return type is pointer to function which first parameter is pointer to pointer of double data type and second parameter is char type data type and return type ispointer to double data type. >;? !ow to read following pointer&

unsigned DD>D>Dptr?V1W>char const D2 ...? 'nswer( 'ssign the priority considering rule of precedence and associati"e.

Now read it following manner( ptr is pointer to array of si/e eight and content of array is pointer to function which first parameter is pointer to character constant and second parameter is "ariable number of arguments and return type is pointer to pointer of unsigned int data type.

-1.

What are the parameter passing con"entions in c&

Gxplanation(

-. pascal( 5n this style function name should >not necessary ? in the uppercase . irst parameter of function call is passed to the first parameter of function definition and so on. 8. cdecl( 5n this style function name can be both in the upper case or lower case. irst parameter of function call is passed to the last parameter of function definition. 5t is default parameter passing con"ention. Gxamples(

-. What will be output of following program& int main>?0 static int a)8*+ "oid cdecl con"->? + "oid pascal con"8>?+ con"->a?+ con"8>a?+ return 7++ 4 "oid cdecl con"->int a2int b? 0 printf>O:d :dO2a2b?+ 4 "oid pascal con"8>int a2int b? 0 printf>ORn:d :dO2a2b?+ 4 Lutput( 8* 7 7 8* >8? What will be output of following program& "oid cdecl fun->int2int?+

"oid pascal fun8>int2int?+ int main>?0 int a)*2b)*+

fun->a2HHa?+ fun8>b2HHb?+ return 7+ 4 "oid cdecl fun->int p2int J?0 printf>Ocdecl( :d :d RnO2p2J?+ 4 "oid pascal fun8>int p2int J?0 printf>Opascal( :d :dO2p2J?+ 4 Lutput( cdecl( ; ; pascal( * ; >B? What will be output of following program& "oid cdecl fun->int2int?+ "oid pascal fun8>int2int?+ int main>?0

int a)*2b)*+

fun->a2HHa?+ fun8>b2HHb?+ return 7+ 4 "oid cdecl fun->int p2int J?0 printf>Ocdecl( :d :d RnO2p2J?+ 4 "oid pascal fun8>int p2int J?0 printf>Opascal( :d :dO2p2J?+ 4 Lutput( cdecl( ; ; pascal( * ; >F? What will be output of following program& "oid con"ention>int2int2int?+ int main>?0 int a)*+

con"ention>a2HHa2aHH?+

return 7+ 4 "oid con"ention>int p2int J2int r?0 printf>O:d :d :dO2p2J2r?+ 4 Lutput( 3 3 * >*? What will be output of following program& "oid pascal con"ention>int2int2int?+ int main>?0 int a)*+

con"ention>a2HHa2aHH?+ return 7+4 "oid pascal con"ention>int p2int J2int r?0 printf>O:d :d :dO2p2J2r?+ 4 Lutput( * ; ; >;? What will be output of following program& "oid pascal con"ention>int2int?+ int main>?0 int a)-+

con"ention>a2HHa?+ return 7+ 4 "oid pascal con"ention>int a2int b?0 printf>O:d :dO2a2b?+ 4 Lutput( - 8 >3? What will be output of following program& "oid con"ention>int2int?+ int main>?0 int a)-+

con"ention>a2HHa?+ return 7+4 "oid con"ention>int a2int b?0 printf>O:d :dO2a2b?+ 4 Lutput( 8 8 -N. What is the far pointer in c&

Gxplanation(

%he pointer which can point or access whole the residence memory of 6'$ i.e. which can access all -; segments is #nown as far pointer.

.i/e of far pointer is F byte or B8 bit. Gxamples( >-? What will be output of following c program& int main>?0 int x)-7+ int far Dptr+ ptr)Tx+ printf>O:dO2si/eof ptr?+ return 7+ 4

Lutput( F >8?What will be output of following c program& int main>?0 int far DnearDptr+ printf>O:d :dO2si/eof>ptr? 2si/eof>Dptr??+ return 7+ 4 Lutput( F 8 Gxplanation( ptr is far pointer while Dptr is near pointer. >B?What will be output of following c program& int main>?0 int far Dp2far DJ+ printf>O:d :dO2si/eof>p? 2si/eof>J??+ 4 Lutput( F F irst -; bit stores( .egment number Next -; bit stores( Lffset address Gxample( int main>?0 int x)-77+ int far Dptr+

ptr)Tx+ printf>O: pO2ptr?+ return 7+ 4 Lutput( 1 D1( F F is offset address

!ere 1 D1 is segment address and in hexadecimal number format.

Note( : p is used for print offset and segment address of pointer in printf function in hexadecimal number format. 5n the header file dos.h there are three macro functions to get the offset address and segment address from far pointer and "ice "ersa. -. P]L >?( %o get offset address from far address.

8. P].GG>?( %o get segment address from far address. B. $^] P>?( %o ma#e far address from segment and offset address. Gxamples( >-?What will be output of following c program& ,include Odos.hO int main>?0 int i)8*+ int farDptr)Ti+ printf>O:9 :9O2 P].GG>ptr?2 P]L 4 >ptr??+

Lutput( 'ny segment and offset address in hexadecimal number format respecti"ely. >8?What will be output of following c program& ,include Odos.hO int main>?0 int i)8*+ int farDptr)Ti+ unsigned int s2o+ s) P].GG>ptr?+ o) P]L >ptr?+

printf>O: pO2$^] P>s2o??+ return 7+ 4 Lutput( 1 DN( F >'ssume?

Note( We cannot guess what will be offset address+ segment address and far address of any far pointer .%hese address are decided by operating system. Limitation of far pointer( We cannot change or modify the segment address of gi"en far address by applying any arithmetic operation on it. %hat is by using arithmetic operator we cannot Uump from one segment to other segment. 5f you will increment the far address beyond the maximum "alue of its offset address instead of incrementing segment address it will repeat its offset address in cyclic order. Gxample(

>J?What will be output of following c program& int main>?0 int i+ char far Dptr)>char D?7xI177 for>i)7+iA)-7+iHH?0 printf>O: p RnO2ptr?+ ptrHH+ 4 return 7+ 4 Lutput( I177( I177( I177( I177( I177( I177( I177(7777 I177(777I177(7778 I177(777B ' I C D G '+

I177(777F %his property of far pointer is called cyclic nature of far pointer within same segment. 5mportant points about far pointer( -. ar pointer compares both offset address and segment address with relational operators. Gxamples( >-?What will be output of following c program& int main>?0 int far Dp)>int D?79378B7777+ int far DJ)>int D?79I78-7777+ if>p))J? printf>OIoth pointers are eJualO?+ else printf>OIoth pointers are not eJualO?+ return 7+ 4 Lutput( Ioth pointers are not eJual >8?What will be output of following c program& int main>?0 int far Dp)>int D?79378B7777+ int far DJ)>int D?79I78-7777+

int near Dx2nearDy+ x)>int near D?p+ y)>int near D?J+ if>x))y? printf>OIoth pointer are eJualO?+ else printf>OIoth pointer are not eJualO?+ return 7+ 4 Lutput( Ioth pointers are eJual 8. ar pointer doesnKt normali/e. 87. What is a cyclic property of data type in c& Gxplain with any example.
Gxplanation(

,includeAstdio.hQ int main>?0 signed char c-)-B7+ signed char c8)@-B7+ printf>O:d :dO2c-2c8?+ return 7+ 4 Lutput( @-8; -8; >why&?

%his situation is #nown as o"erflow of signed char. 6ange of unsigned char is @-81 to -83. 5f we will assign a "alue greater than -83 then "alue of "ariable will be changed to a "alue if we will mo"e cloc#wise direction as shown in the figure according to number. 5f we will assign a number which is less than @-81 then we ha"e to mo"e in anti@cloc#wise direction.

Data type Juestions in c


Data types interview Muestions and answers
$t is freMuently as'ed technical o%&ective types multiple choice Muestions of placement in c programming language

-.
!hat will %e output when you will execute following c code; CincludeDstdio(hE

int main+-9 printf+QHdRtQ)siNeof+>(/--1 printf+QHdRtQ)siNeof+?0000--1 printf+QHdQ)siNeof+WAW--1 return 01 : Choose all that apply* )$* 8 4 , )+* A 4 , )C* 8 8 , )D* A 8 , )E* A 8 4
Lutput ( >G?

G x p l a n a t i o n (
#ur%o COO 7(0* A 8 4 #ur%o C OO8(/* A 8 4 [inux GCC* A 8 8 =isual COO* A 8 8 By default data type of numeric constants is* >(/ * dou%le ?0000* long int XAY* char $n C siNe of data type varies from compiler to compiler( $n #UKBJ C 7(0 +,> %it compilers- siNe of* dou%le is A %yte [ong int is 8 %yte Character constant is 4 %yte +siNe of char data type is one %yte$n #UKBJ C 8(/ or [inux GCC compilers +74 %it compilers- siNe of* dou%le is A %yte long int is A %yte Character constant is 4 %yte

8.
+iConsider on following declaring of enum( enum cric'et 9Gam%hir)Smith)Sehwag:c1

+iienum cric'et 9Gam%hir)Smith)Sehwag:1 +iii- enum 9Gam%hir)Smith.P/)Sehwag:c1 +ivenum c 9Gam%hir)Smith)Sehwag:1 Choose correct one*
)$*

Jnly +i- is correct declaration )+* Jnly +i- and +ii- is correct declaration )C* Jnly +i- and +iii- are correct declaration )D* Jnly +i-)+ii- and are correct declaration )E* All four are correct declaration
Lutput ( >G?

G x p l a n a t i o n (
Syntax of enum data type is* enum 5Dtag]nameE69 Denum]constanat]nameE 5.Dinteger] valueE6) ^ : 5Dvar]nameE)^6 ote* 56 * Kepresents optional ( DE* Kepresents any valid c identifier

B.
!hat will %e output when you will execute following c code; CincludeDstdio(hE int main+-9 signed x1 unsigned y1 x . ,0 OP ,0u O ,0u OP ,01 y . x1 if+x..yprintf+QHd HdQ)x)y-1 else if+x\.yprintf+QHu HuQ)x)y-1 return 01 : Choose all that apply* )$* 0 0

>//7> P,0 )C* 0 >//7> )D* >//7> 0 )E* Compilation error


)+* Lutput ( >'?

G x p l a n a t i o n (
#ur%o COO 7(0* 0 0 #ur%o C OO8(/* 0 0 [inux GCC* 0 0 =isual COO* 0 0 Consider on the expression* x . ,0 OP ,0u O ,0u OP ,01 ,0* $t is signed integer constant( ,0u* $t is unsigned integer constant( S* $t is signed integer varia%le( $n any %inary operation of dissimilar data type for example* a O % [ower data type operand always automatically type casted into the operand of higher data type %efore performing the operation and result will %e higher data type( As we 'now operators en&oy higher precedence than %inary operators( So our expression is* x . ,0 O +P,0u- O ,0u O +P,0-1 . ,0 O P,0 O ,0 O +P,0-1 . 0 ote* Signed is higher data type than unsigned int( So) Corresponding signed value of unsigned ,0u is O,0

F.
!hich of the following is not modifier of data type in c; extern )+* interrupt )C* huge )D* register )E* All of these are modifiers of data type
)$*

Lutput ( >G?

G x p l a n a t i o n (
#o 'now more a%out these go to following lin'*

*.
!hat will %e output when you will execute following c code; CincludeDstdio(hE int main+-9 dou%le num./(41 int var./1 printf+QHdRtQ)siNeof+\num--1 printf+QHdRtQ)siNeof+var.,/F4--1 printf+QHdQ)var-1 return 01 : Choose all that apply* )$* 8 4 @ )+* 8 8 / )C* 4 4 / )D* 4 8 @ )E* A 4 @
Lutput ( >C?

G x p l a n a t i o n (
#ur%o COO 7(0* 4 4 / #ur%o C OO8(/* 4 4 / [inux GCC* 8 8 / =isual COO* 8 8 / siNeof+<xproperator always returns the an integer value which represents the siNe of the final value of the expression expr( Consider on the following expression* \num .\/(4 .0

0 is int type integer constant and it siNe is 4 %y in #UKBJ C 7(0 compiler and 8 in the #UKBJ C 8(/ and [inux GCC compilers( Consider on the following expression* var . ,/F4 .E var . @ .E @ @ is int type integer constant( Any expression which is evaluated inside the siNeof operator its scope always will %e within the siNeof operator( So value of varia%le var will remain / in the printf statement(

;.
!hat will %e output when you will execute following c code; CincludeDstdio(hE int main+-9 const int 2p1 int a.,01 p.3a1 printf+QHdQ)2p-1 return 01 : Choose all that apply* )$* 0 )+* ,0 )C* Gar%age value )D* Any memory address )E* <rror* Cannot modify const o%&ect
Lutput ( >I?

G x p l a n a t i o n (
#ur%o COO 7(0* ,0 #ur%o C OO8(/* ,0 [inux GCC* ,0 =isual COO* ,0 $n the following declaration const int 2p1

p can 'eep address of constant integer(

3.
Consider on following declaration* +ishort i.,01 +iistatic i.,01 +iii- unsigned i.,01 +ivconst i.,01 Choose correct one*
)$*

Jnly +iv- is incorrect )+* Jnly +ii- and +iv- are incorrect )C* Jnly +ii-)+iii- and +iv- are correct )D* Jnly +iii- is correct )E* All are correct declaration
Lutput ( >G?

G x p l a n a t i o n (
Default data type of a%ove all declaration is int(

1.
!hat will %e output when you will execute following c code; CincludeDstdio(hE int main+-9 int a. siNeof+signed- OsiNeof+unsigned-1 int %.siNeof+const-OsiNeof+volatile-1 printf+QHdQ)aOOO%-1 return 01 : Choose all that apply* )$* ,0 )+* ? )C* A )D* <rror* Cannot find siNe of modifiers )E* <rror* Undefined operator OOO
Lutput ( >C?

G x p l a n a t i o n (

#ur%o COO 7(0* A #ur%o C OO8(/* A [inux GCC* ,> =isual COO* ,> Default data type of signed) unsigned) const and volatile is int( $n tur%o c 7(0 siNe of int is two %yte( So) a . 8 and % .8 ow) aOOO% . aOO O % . 8 O 8 FFdue to post increment operator( .A ote* $n tur%o c 8(/ and [inux gcc compiler siNe of int is 8 %yte so your out will %e ,>

N.
!hat will %e output when you will execute following c code; CincludeDstdio(hE int main+-9 signed x)a1 unsigned y)%1 a.+signed-,0u1 %.+unsigned-P,01 y . +signed-,0u O +unsigned-P,01 x . y1 printf+QHd HuRtQ)a)%-1 if+x..yprintf+QHd HdQ)x)y-1 else if+x\.yprintf+QHu HuQ)x)y-1 return 01 : Choose all that apply* 0 0 )$* ,0 P,0 >//,> P,0 )+* ,0 P,0 ,0 P,0 )C* ,0 P,0 0 0 )D* ,0 >//4> )E* Compilation error

Lutput ( >D?

G x p l a n a t i o n (
#ur%o COO 7(0* ,0 >//4> 0 0 #ur%o C OO8(/* ,0 >//4> 0 0 [inux GCC* ,0 84?8?>@4A> 0 0 =isual COO* ,0 84?8?>@4A> 0 0 a.+signed-,0u1 signed value of ,0u is O,0 so) a.,0 %.+unsigned-P,01 unsigned value of P,0 is * MAS]=A[U<]J"]U S$G <D]$ # _ ,0 O , $n tur%o c 7(0 complier max value of unsigned int is >//7/ So) % . >//4> y . +signed-,0u O +unsigned-P,01 . ,0 O >//4> . >//7> . 0 +Since >//7> is %eyond the range of unsigned int( Nero is its corresponding cyclic vlaueS . y . 0

-7.
!hich of the following is integral data type; void )+* char )C* float )D* dou%le )E* one of these
)$* Lutput ( >I?

G x p l a n a t i o n (
$n c char is integral data type( $t stores the ASC$$ value of any character constant(

--.

!hat will %e output when you will execute following c code; CincludeDstdio(hE int main+-9 volatile int a.,,1 printf+QHdQ)a-1 return 01 : Choose all that apply* )$* ,, )+* Gar%age )C* P4 )D* !e cannot predict )E* Compilation error
Lutput ( >D?

G x p l a n a t i o n (
#ur%o COO 7(0* !e cannot predict #ur%o C OO8(/* !e cannot predict [inux GCC* !e cannot predict =isual COO* !e cannot predict !e cannot predict the value of volatile varia%le %ecause its value can %e changed %y any microprocessor interrupt(

-8.
!hat is the range of signed int data type in that compiler in which siNe of int is two %yte; )$* P4// to 4// )+* P74@>@ to 74@>@ )C* P74@>A to 74@>A )D* P74@>@ to 74@>A )E* P74@>A to 74@>@
Lutput ( >G?

G x p l a n a t i o n (
ote* SiNe of int is always eMual to word length of micro preprocessor in which your compiler has %ased(

-B.
!hat will %e output when you will execute following c code; CincludeDstdio(hE const enum Alpha9 X) Y./) Z :p.,01 int main+-9 enum Alpha a)%1 a. X1 %. Z1 printf+QHdQ)aO%Pp-1 return 01 : Choose all that apply* )$* P8 )+* P/ )C* ,0 )D* ,, )E* <rror* Cannot modify constant o%&ect
Lutput ( >'?

G x p l a n a t i o n (
#ur%o COO 7(0* P8 #ur%o C OO8(/* P8 [inux GCC* P8 =isual COO* P8 Default value of enum constant S is Nero and ` . L O , . / O , . > So) a O % _ p .0 O > P,0 . P8

-F.
!hat will %e output when you will execute following c code;

CincludeDstdio(hE int main+-9 char a.4/01 int expr1 expr. aO \a O Va O OOa1 printf+QHdQ)expr-1 return 01 : Choose all that apply* )$* 48? )+* 4/0 )C* 0 )D* P> )E* Compilation error
Lutput ( >D?

G x p l a n a t i o n (
#ur%o COO 7(0* P> #ur%o C OO8(/* P> [inux GCC* P> =isual COO* P> char a . 4/01 4/0 is %eyond the range of signed char( $ts corresponding cyclic value is* P> So) a . P> Consider on the expression* expr. aO \a O Va O OOa1 Jperator\ ) V and OO have eMual precedence( And it associative is right to left( So) "irst OO operator will perform the operation( So value a will P/ ow) <xpr . P/ O \P/ O VP/ O P/ . P/ O \P/ O 8 P / . P/ O 0 O 8 P/ . P>

-*.

Consider on order of modifiers in declaration* +i-char volatile register unsigned c1 +ii-volatile register unsigned char c1 +iii-register volatile unsigned char c1 +iv-unsigned char volatile register c1 Jnly +ii- is correct declaration )+* Jnly +i- is correction declaration )C* All are incorrect )D* All are correct %ut they are different )E* All are correct and same
)$* Lutput ( >G?

following

G x p l a n a t i o n (
Jrder of modifier of varia%le in c has not any significant( Choose correct one*

-;.
!hat will %e output when you will execute following c code; CincludeDstdio(hE int main+-9 int a.P/1 unsigned int %.P/u1 if+a..%printf+QAvatarQ-1 else printf+QAlienQ-1 return 01 : Choose all that apply* )$* Avatar )+* Alien )C* Kun time error )D* <rror* $llegal assignment )E* <rror* DonYt compare signed no( with unsigned

no(
Lutput ( >'?

G x p l a n a t i o n (
#ur%o COO 7(0* Avatar #ur%o C OO8(/* Avatar [inux GCC* Avatar =isual COO* Avatar int a.P/+ Here varia%le a is %y default signed int( unsigned int %.P/u1 Constant P/u will convert into unsigned int( $ts corresponding unsigned int value will %e * >//7> _ / O ,. >//74 So) % . >//74 $n any %inary operation of dissimilar data type for example* a .. % [ower data type operand always automatically type casted into the operand of higher data type %efore performing the operation and result will %e higher data type( $n c signed int is higher data type than unsigned int( So varia%le % will automatically type casted into signed int( So corresponding signed value of >//74 is P/ Hence) a..%

-3.
!hat will %e output when you will execute following c code; CincludeDstdio(hE extern enum cric'et x1 int main+-9 printf+QHdQ)x-1 return 01 : const enum cric'et9 Taylor) Kallis.,@)

Chanderpaul :x.TaylorTKallis3Chanderpaul1 Choose all that apply* )$* 0 )+* ,/ )C* ,> )D* ,@ )E* Compilation error
Lutput ( >C?

G x p l a n a t i o n (
#ur%o COO 7(0* ,> #ur%o C OO8(/* Compilation error [inux GCC* Compilation error =isual COO* ,> x.TaylorTKallis3Chanderpaul = 0 | 17 & 18 = 0 |(17 & 18) //& operator en oy hi!her pre"eden"e than | =0 |1# =1#

-1.
!hich of the following is not derived data type in c; "unction )+* Pointer )C* <numeration )D* Array )E* All are derived data type
)$* Lutput ( >C?

G x p l a n a t i o n (
<num is primitive data type(

-N.
!hat will %e output when you will execute following c code;

CincludeDstdio(hE enum A9 $)y./) enum B9 p.,0)M :varp1 :varx1 int main+-9 printf+QHd HdQ)x)varp(M-1 return 01 : Choose all that apply* )$* 0 ,, )+* / ,0 )C* 8 ,, )D* 0 ,0 )E* Compilation error
Lutput ( >G?

G x p l a n a t i o n (
#ur%o COO 7(0* Compilation error #ur%o C OO8(/* Compilation error [inux GCC* Compilation error =isual COO* Compilation error
esting of enum constant is not possi%le in c(

87.
Consider on following declaration in c* +i-short const register i.,01 +ii-static volatile const int i.,01 +iii-unsigned auto long register i.,01 +iv-signed extern float i.,0(01 Choose correct one* )$* Jnly +iv-is correct )+* Jnly +ii- and +iv- is correct )C* Jnly +i- and +ii- is correct )D* Jnly +iii- correct

)E* All are Lutput ( >C?

correct declaration

G x p l a n a t i o n (
Jption +$$$- is in correct due to we cannot specify two storage class auto and register in the declaration of any varia%le( Jption +iv- is in correct due to we cannot use signed or unsigned modifiers with float data type( $n c float data type %y default signed and it cannot %e unsigned(

Looping Xuestion

Looping Xuestion and 'nswer


+,- !hat will %e output of following c code; CincludeDstdio(hE extern int x1 int main+-9 do9 do9 printf+QHoQ)x-1 : while+\P4-1 : while+0-1 return 01 : int x.A1
EXPLANATION

Jutput* ,0 <xplanation* Here varia%le x is extern type( So it will search the definition of varia%le x( which is present at the end of the code( So value of varia%le x .A #here are two doPwhile loops in the a%ove code( AS we 'now doPwhile executes at least one time even

that condition is false( So program control will reach at printf statement at it will print octal num%er ,0 which is eMual to decimal num%er A( ote* Ho is used to print the num%er in octal format( $n inner doP while loop while condition is \ P4 . 0 $n C Nero means false( Hence program control will come out of the inner doPwhile loop( $n outer doP while loop while condition is 0( #hat is again false( So program control will also come out of the outer doPwhile loop(

+4- !hat will %e output of following c code; CincludeDstdio(hE int main+-9 int i.4)&.41 while+iO,;PPi*&OOprintf+QHdQ)i-1 return 01 :
EXPLANATION

Jutput* , <xplanation* Consider the while loop condition* i O , ; PP i * O O& $n first iteration* i O , . 7 +#rueSo ternary operator will return P_i i(e( , $n c , means true so while condition is true( Hence printf statement will print , $n second iteration* iO , . 4 +#rueSo ternary operator will return P_i i(e( 0 $n c Nero means false so while condition is false( Hence program control will come out of the while

loop(

+7- !hat will %e output of following c code; CincludeDstdio(hE int main+-9 int x.0,,)i1 for+i.01iDx1iO.7-9 printf+QStart Q-1 continue1 printf+Q<ndQ-1 : return 01 :
EXPLANATION

Jutput* Start Start Start <xplantion* 0,, is octal num%er( $ts eMuivalent decimal value is ?( So) x . ? "irst iteration* i . 0 i D x i(e( 0 D ? i(e( if loop condition is true( Hence printf statement will print* Start Due to continue 'eyword program control will come at the %eginning of the for loop and value of varia%le i will %e* i O. 7 i . i O 7 . 7 Second iteration* i . 7 i D x i(e( 7 D ? i(e( if loop condition is true( Hence printf statement will print* Start Due to continue 'eyword program control will come at the %eginning of the for loop and value of varia%le i will %e* i O. 7 i . i O 7 . >

#hird iteration* i . 7 i D x i(e( > D ? i(e( if loop condition is true( Hence printf statement will print* Start Due to continue 'eyword program control will come at the %eginning of the for loop and value of varia%le i will %e* i O. 7 i . i O 7 . ? fourth iteration* i . > i D x i(e( ? D ? i(e( if loop condition is false( Hence program control will come out of the for loop(

+8- !hat will %e output of following c code; CincludeDstdio(hE int main+-9 int i)&1 i.&.4)71 while+PPi33&OOprintf+QHd HdQ)i)&-1 return 01 :
EXPLANATION

Jutput* ,7 <xplanation* $nitial value of varia%le i . 4 & . 4

Consider the while condition * PPi 33 &OO $n first iteration* PPi 33 &OO . , 33 4 FF$n c any nonPNero num%er represents true( . , +#rueSo while loop condition is true( Hence printf function will print value of i . , and & . 7 +Due to post increment operator$n second iteration* PPi 33 &OO . 0 33 7 FF$n c Nero represents false . 0 FF"alse So while loop condition is false( Hence program control will come out of the for loop(

+/- !hat will %e output of following c code; CincludeDstdio(hE int main+-9 static int i1 for+OOi1OOi1OOi- 9 printf+QHd Q)i-1 if+i..8- %rea'1 : return 01 :
EXPLANATION

Jutput* 48 <xplanation*

Default value of static int varia%le in c is Nero( So) initial value of varia%le i . 0 "irst iteration* "or loop starts value* OOi i(e( i . 0 O , . , "or loop condition* OOi i(e( i . , O , . 4 i(e( loop condition is true( Hence printf statement will print 4 [oop incrimination* OO$ i(e( i . 4 O , .7 Second iteration* "or loop condition* OOi i(e( i . 7 O , . 8 i(e( loop condition is true( Hence printf statement will print 8( Since is eMual to for so if condition is also true( But due to %rea' 'eyword program control will come out of the for loop(

+>- !hat will %e output of following c code; CincludeDstdio(hE int main+-9 int i.,1 for+i.01i.P,1i.,- 9 printf+QHd Q)i-1 if+i\.,- %rea'1 : return 01 :
EXPLANATION

Jutput* P, <xplanation* $nitial value of varia%le i is ,( "irst iteration* "or loop initial value* i . 0 "or loop condition* i . P, ( Since P, is nonP Nero num%er( So loop condition true( Hence printf function will print value of varia%le i i(e( P,

Since varia%le i is not eMual to ,( So) if condition is true( Due to %rea' 'eyword program control will come out of the for loop(

+@- !hat will %e output of following c code; CincludeDstdio(hE int main+-9 for+11- 9 printf+QHd Q),0-1 : return 01 :
EXPLANATION

Jutput* $nfinite loop <xplanation* $n for loop each part is optional(

+A- !hat will %e output of following c code; CincludeDstdio(hE int r+-1 int main+-9 for+r+-1r+-1r+-- 9 printf+QHd Q)r+--1 : return 01 : int r+-9 int static num.@1 return numPP1 :
EXPLANATION

Jutput* / 4

<xplanation* "irst iteration* [oop initial value* r+- . @ [oop condition* r+- . > Since condition is true so printf function will print r+- i(e( / [oop incrimination* r+- . 8 Second iteration* [oop condition* r+- . 7 Since condition is true so printf function will print r+- i(e( 4 [oop incrimination* r+- . , #hird iteration* [oop condition* r+- . 0 Since condition is false so program control will come out of the for loop(

+?- !hat will %e output of following c code; CincludeDstdio(hE Cdefine p+a)%- aCC% Cdefine call+x- Cx int main+-9 do9 int i.,/)&.71 printf+QHdQ)p+iPO)O&--1 : while+2+call+>4/-O7--1 return 01 :
EXPLANATION

Jutput* ,, <xplanation* "irst iteration* p+iPO)O&.iPOO& FF aCC% .i P OO&

.,/ _ 8 . ,, !hile condition is * 2+call+>4/-O 7. 2+G>4/I O 7ote* C preprocessor operator convert the operand into the string( .2+$t will return the memory address of character XR0Y. XR0Y . 0 FFASC$$ value of character null character Since loop condition is false so program control will come out of the for loop(

+,0- !hat will %e output of following c code; CincludeDstdio(hE int main+-9 int i1 for+i.01iD./1iOO-1 printf+QHdQ)ireturn 01 :
EXPLANATION

Jutput* > <xplanation* $t possi%le for loop without any %ody( +,,- !hat will %e output of following c code; CincludeDstdio(hE int i.801 extern int i1 int main+-9 do9 printf+QHdQ)iOO-1 : while+/)8)7)4),)0-1

return 01

EXPLANATION

Jutput* 80 <xplanation* $nitial value of varia%le i is 80 "irst iteration* printf function will print iOO i(e( 80 do P while condition is * +/)8)7)4),)0Here comma is %ehaving as operator and it will return 0( So while condition is false hence program control will come out of the for loop( +,4- !hat will %e output of following c code; CincludeDstdio(hE char ]x]+int)(((-1 int main+-9 char +2p-+int)(((-.3]x]1 for+1+2p-+0),)4)7)8-1 printf+QHdQ)\O4-1 return 01 : char ]x]+int a)(((-9 static i.P,1 return iOOOa1 :
EXPLANATION

Jutput* 0 <xplanation* $n c three continuous dot represents varia%le num%er of arguments( p is the pointer to the function ]x] "irst iteration of for loop* $nitial value* othing FF $n c it is optional [oop condition* +2p-+0),)4)7)8. 2+3]x]-+0),)4)7)8- MM p ) T]x]

. ]x]+0),)4)7)8- MMD and T always cancel to each other . return iOOOa . return iO OOa . return P, O , . 0 Since condition is false( But printf function will print 0( $t is %ug of c language(
+,7- !hat will %e output of following c code; CincludeDstdio(hE int main+-9 int i1 for+i.,01iD.,/1iOO-9 while+i-9 do9 printf+QHd Q),-1 if+iEE,continue1 :while+0-1 %rea'1 : : return 01 :
EXPLANATION

Jutput* , , , , , , "or loop will execute six times( ote* continue 'eyword in doPwhile loop %ring the program its while condition +while+0-- which is always false(

+,8- How many times this loop will execute; CincludeDstdio(hE int main+-9

char c.,4/1 do printf+QHd Q)c-1 while+cOO-1 return 01

EXPLANATION

Jutput* "inite times <xplanation* $f we will increment the char varia%le c it will increment as* ,4>),4@)P,4A)P,4@),4> ( ( ( ( ) 7) 4) ,) 0 !hen varia%le c . 0 then loop will terminate(

+,/- !hat will %e output of following c code; CincludeDstdio(hE int main+-9 int x.,471 int i.9 printf+QcQ QOOQ:1 for+x.01xD.i1xOO-9 printf+QHx Q)x-1 : return 01 :
EXPLANATION

Jutput* cOO0 , 4 7 <xplanation* "irst printf function will print* cOO and return 7 to varia%le i( "or loop will execute three time and printf function will print 0) ,) 4 respectively(

C programming preprocessor Muestions explanations +,- !hat will %e output of following CincludeDstdio(hE Cdefine max ,0 int main+-9 int i1 i.OOmax1 printf+QHdQ)i-1 return 01 : +4- !hat will %e output of following CincludeDstdio(hE Cdefine max ,0O4 int main+-9 int i1 i.max2max1 printf+QHdQ)i-1 return 01 : +7- !hat will %e output of following CincludeDstdio(hE Cdefine A 8P4 Cdefine B 7P, int main+-9 int ratio.AFB1 printf+QHd Q)ratio-1 return 01 : +8- !hat will %e output of following CincludeDstdio(hE Cdefine MA +x)y- +x-E+y-;+x-*+yint main+-9 int i.,0)&.?)'.01 '.MA +iOO)OO&-1 printf+QHd Hd HdQ)i)&)'-1 return 01 : +/- !hat will %e output of following CincludeDstdio(hE

and code;

code;

code;

code;

code;

Cdefine S#AK# main+- 9 Cdefine PK$ # printf+Q2222222Q-1 Cdefine < D : S#AK# PK$ # < D +>- !hat will %e output of following code; Cdefine CUB<+x- +x2x2xCdefine M / Cdefine MO, Cdefine PK$ # printf+QZPQ-1 int main+-9 int volume .CUB<+7O4-1 printf+QHd Hd Q)volume) -1 PK$ # return 01 : Solution section +,output* compiler error( <xplanation* Here %a$ is preprocessor macro sym%ol which process first %efore the actual compilation( "irst preprocessor replace the sym%ol to its value in entire the program %efore the compilation( So in this program max will %e replaced %y ,0 %efore compilation( #hus program will %e converted li'e this* int main+-9 int i1 i.OO,01 printf+QHdQ)i-1 return 01 :

$n this program constant sym%ol(

we

are

trying

to

increment

Meaning of OO,0 is* ,0.,0O, or ,0.,, !hich is error %ecause we cannot assign constant value to another constant value (Hence compiler will give error( +4Jutput* 74 <xplanation* Here max is preprocessor macro sym%ol which process first %efore the actual compilation start( Preprocessor replace the sym%ol to its value in entire the program %efore the compilation( So in this program max will %e replaced %y ,0O4 %efore compilation( #hus program will %e converted as* int main+-9 int i1 i.,0O42,0O41 printf+QHdQ)i-1 return 01 : now i.,0O42,0O4 i.,0O40O4 i.74 +7Jutput* <xplanation* 7

A and B are preprocessor macro sym%ol which process

first %efore the actual compilation start( Preprocessor replace the sym%ol to its value in entire the program %efore the compilation( So in this program A and B will %e replaced %y 8P4 and 7P , respectively %efore compilation( #hus program will %e converted as* int main+-9 int ratio.8P4F7P,1 printf+QHd Q)ratio-1 return 01 : Here ratio.8P4F7P, ratio.8P0P, ratio.7 +8Jutput* ,, ,, ,, <xplanation* PreprocessorYs macro which process first %efore the actual compilation( #hus program will %e converted as* int main+-9 int i.,0)&.?)'.01 '.+iOO-E+OO&-;+iOO-*+OO&-1 printf+QHd Hd HdQ)i)&)'-1 return 01 : now '.+iOO-E+OO&-;+iOO-*+OO&-1 first it will chec' the condition +iOO-E+OO&iOO i(e( when postfix is used with varia%le in

expression then expression is evaluated first with original value then varia%le is incremented Jr ,0E,0 #his condition is false( ow i . ,0O, . ,, #here is rule) only false part will execute after; i(e( OO&) iOO will %e not execute( So after OO& &.,0O,.,,1 And ' will assign value of & (so '.,,1 +/Jutput* 2222222 <xplanation* #his program will %e converted as* main+-9 printf+Q2222222Q-1 : +>Jutput* ,@ > <xplanation* #his program will %e converted as* int main+-9 int volume .+7O427O427O4-1 printf+QHd Hd Q)volume)/O,-1 PK$ # return 01 :

Printf 2 .canf Xuestion Printf function Juestions and answer with solution
Printf o%&ective types interview Muestions and answers

+,- !hat will output when you compile and run the %elow code; CincludeDstdio(hE CincludeDconio(hE void main+9 int a./)%.>)c.,,1 clrscr+-1 printf+QHd Hd HdQ-1 getch+-1 : +a-Gar%age value gar%age value gar%age value +%-/ > ,, +c-,, > / +d-Compiler error Answer* +c+4- !hat will output when you compile and run the %elow code; CincludeDstdio(hE void main+9 char 2str.QC#<CH J#$PSQ1 clrscr+-1 printf+strO@-1 getch+-1 : +a-C#<CH J#$PS +%-C#<CH J +c-#$PS +d-Compiler error Answer* +c+7- !hat will output when you compile and run the Below code; CincludeDstdio(hE void main+9 clrscr+-1 printf+QHdQ)printf+QC#<CH J#$PSQ--1

: +a-,,C#<CH J#$PS +%-C#<CH J#$PS,, +c-Gar%age C#<CH J#$PS +d-Compiler error Answer* +%+8- !hat will output when you compile and run the Below code; CincludeDstdio(hE CincludeDconio(hE void main+9 short int a./1 clrscr+-1 printf+QHdQO,)a-1 getch+-1 : +a-> +%-/, +c-d +d-Compiler error Answer* +c+/- !hat will output when you compile and run the Below code; CincludeDstdio(hE void main+9 int i.A/1 clrscr+-1 printf+QHp H"pQ)i)i-1 getch+-1 : +a-A/ A/ +%-00// 078<*00// +c-00// """"*00// +d-Compiler error

getch+-1

Answer* +%+>- !hat will output when you compile and run the Below code; CincludeDstdio(hE static struct student 9 int a1 int %1 int c1 int d1 :s,.9>)@)A)?:)s4.98)7)4),:)s71 void main+9 s7.s,Os41 clrscr+-1 printf+QHd Hd Hd HdQ)s7(a)s7(%)s7(c)s7(d-1 getch+-1 : +a->@A? +%-874, +c-,0,0,0,0 +d-Compiler error Answer* +d+@- !hat will output when you compile and run the Below code; CincludeDstdio(hE extern struct student 9 int a1 int %1 int c1 int d1 :s.9>)@)A)?:1 void main+9 clrscr+-1

printf+QHd Hd Hd HdQ)s(a)s(%)s(c)s(d-1 getch+-1 : +a->@A? +%-?A@> +c-0000 +d-Compiler error Answer* +a+A- !hat will output when you compile and run the Below code; CincludeDstdio(hE struct student 9 static int a1 register int %1 auto int c1 extern int d1 :s.9>)@)A)?:1 void main+9 printf+QHd Hd H HdQ)s(a)s(%)s(c)s(d-1 : +a->@A? +%-?A@> +c-0000 +d-Compiler error Answer* +d+?-!hat will output when you compile and run the Below code; CincludeDstdio(hE struct student 9 int roll1 int cgpa1 int sgpa5A61 :1 void main+-

struct student s.9,4)A)@)4)/)?:1 int 2ptr1 ptr.+int 2-3s1 clrscr+-1 printf+QHdQ)2+ptrO7--1 getch+-1

+a-A +%-@ +c-4 +d-Compiler error Answer* +c+,0- !hat will output when you compile and run the Below code; CincludeDstdio(hE struct game 9 int level1 int score1 struct player 9 char 2name1 :g4.9QanilQ:1 :g7.9,0)400:1 void main+9 struct game g,.g71 clrscr+-1 printf+QHd Hd HsQ)g,(level)g,(score)g,(g4(name-1 getch+-1 : +a-,0 400 anil +%-400 ,0 anil +c-,0 400 null +d-Compiler error Answer* +d-

+,,-!hat will output when you compile and run the Below code; CincludeDstdio(hE struct game 9 int level1 int score1 struct player 9 char 2name1 :g41 :g,1 void main+9 clrscr+-1 printf+QHd Hd HsQ)g,(level)g,(score)g,(g4(name-1 getch+-1 : +a-Gar%age]value gar%age]value gar%age]value +%-0 0 +null+c-Kun time error +d-Compiler error Answer* +%-

.tring Juestions .tring Juestions with solution of c programming.


String Muestions in c interview Answer and explanation of Muestions are %ased on tur%o c 7(0 compilers( Answer and explanation may vary in other compilers(

-.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 char arr5@6.Q etwor'Q1 printf+QHsQ)arr-1

: Choose all that apply* )$* etwor'


)+*

Gar%age value )D* Compilation error )E* one of the a%ove


)C*

Lutput ( >C?

Gxplanation(
SiNe of a character array should one greater than total num%er of characters in any string which it stores( $n c every string has one terminating null character( #his represents end of the string(

So in the string G etwor'I ) there are A characters and they are X Y)YeY)YtY)YwY)YoY)YrY)Y'Y and XR0Y( SiNe of array arr is seven( So array arr will store only first sevent characters and it will note store null character( As we 'now Hs in printf statement prints stream of characters until it doesnYt get first null character( Since array arr has not stored any null character so it will print gar%age value(

8.
!!hat will %e output when you will following c code; CincludeDstdio(hE void main+-9 char arr5,,6.Q#he African aueenQ1 printf+QHsQ)arr-1 : Choose all that apply* )$* #he African aueen )+* #he execute

#he African )D* Compilation error )E* one of the a%ove


)C*

Lutput ( >D?

Gxplanation(
SiNe of any character array cannot %e less than the num%er of characters in any string which it has assigned( SiNe of an array can %e eMual +excluding null character- or greater than %ut never less than(

B.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int const S$`<./1 int expr1 dou%le value5S$`<6.94(0)8(0)>(0)A(0),0(0:1 expr.,T4T7T81 printf+QHfQ)value5expr6-1 : Choose all that apply* )$* 4(000000 )+* 8(000000 )C* A(000000 )D* Compilation error )E* one of the a%ove

Lutput ( >D?

Gxplanation(
SiNe of any varia%le( array in c cannot %e constantan

F.
!hat will %e output when you will execute following c code;

CincludeDstdio(hE enum power9 &alai) 'ladi%ir.7) (ara")) *illary :1 void main+-9 float leader5&alaiO*illary6.9,(f)4(f)7(f)8(f)/( f:1 enum power p.(ara")1 printf+QH0(fQ)leader5pEE,O,6-1 : Choose all that apply* )$* , )+* 4 )C* 7 )D* Compilation error )E* one of the a%ove

Lutput ( >I?

Gxplanation(
SiNe of an array can %e enum constantan( =alue of enum constant Barac' will eMual to =ladimir O , . 7 O, . 8 So) value of enum varia%le p . 8 leader5p EE , O,6 . leader58 EE ,O,6 .leader58 EE 46 FFO operator en&oy higher precedence than EE operator( .leader5,6 FF8EE4 . +8 F +4U4- . 8F8 . , .4

*.
!hat will %e output when you will execute following c code; CincludeDstdio(hE Cdefine var 7 void main+-9

: Choose all that apply* )$* a )+* r )C* l )D* Compilation error )E* one of the a%ove

char 2cric'et5varOV06.9Qclar'eQ)Q'allisQ:1 char 2ptr.cric'et5,OV061 printf+QHcQ)2OOptr-1

Lutput ( >C?

Gxplanation(
$n the expression of siNe of an array can have micro constant( var OV0 . 7 O V0 . 7 O +P,- . 4 [etYs assume string Gclar'eI and G'allisI has stored at memory address ,00 and /00 respectively as shown in the following figure* "or string Gclar'eI*

"or string G'allisI*

$n this program cric'et is array of characterYs pointer of siNe 4( So array cric'et will 'eep the memory address of first character of %oth strings i(e( content of array cric'et is* cric'et546 . 9,00)/00: ptr is character pointer which is pointing to the fist element of array cric'et( So) ptr . ,00 ow consider on 2OOptr Since ptr . ,00 so after OOptr ) ptr . ,0, 2+OOptr- . 2+,0,- . content of memory address ,0,( "rom a%ove figure it is clear that character is l(

;.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 char data546576546.90),)4)7)8)/)>)@)A)?),0),,:1 printf+QHoQ)data5065465,6-1 : Choose all that apply* )$* / )+* > )C* @ )D* Compilation error )E* one of the a%ov

Lutput ( >'?

Gxplanation(
Ho in printf statement is used to print num%er in the octal format(

3.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 short num576546.97)>)?),4),/),A:1 printf+QHd HdQ)2+numO,-5,6)22+numO4--1 : Choose all that apply* )$* ,4 ,A )+* ,A ,A )C* ,/ ,/ )D* ,4 ,/ )E* Compilation error

Lutput ( >C?

Gxplanation(
2+numO,-5,6

.2+2++numO,-O,-.2+2+numO4-.2+num546.num546506 .,/ And 22+numO4.2+num546O0.num546506 .,/

1.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 char 2ptr.QctechnotipsQ1 printf+QHdQ)P75ptr6-1 : Choose all that apply* )$* Gar%age value )+* P700 )C* P?? )D* Compilation error )E* one of the a%ove

Lutput ( >C?

Gxplanation(
P75ptr6 .P2+7Optr.P2+ptrO7.Pptr576 .P?? FFASC$$ value of character XcY is ??

N.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9

long myarr546586.90l),l)4l)7l)8l)/l)>l)@l:1 printf+QHldRtQ)myarr5,6546-1 printf+QHldHldRtQ)2+myarr5,6O7-)75myarr5,66-1 printf+QHldHld HldRtQ )2+2+myarrO,-O4-)2+,5myarr6O4-)75,5myarr66-1 : Choose all that apply* / >> @@> )+* > @@ >>@ )C* > >> @@> )D* Compilation error )E* one of the a%ove
)$*

Lutput ( >I?

Gxplanation(
#hin' yourself(

-7.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int array546576.9/),0),/)40)4/)70:1 int +2ptr-546576.3array1 printf+QHdRtQ)222ptr-1 printf+QHdRtQ)222+ptrO,--1 printf+QHdRtQ)22+2ptrO,--1 printf+QHdRtQ)2+2+2ptrO,-O4--1 : Choose all that apply* )$* / Gar%age 40 70 )+* ,0 ,/ 70 40 )C* / ,/ 40 70 )D* Compilation error )E* one of the a%ove

Lutput ( >'?

Gxplanation(
ptr is pointer to two dimension array( 222ptr .2223array FFptr . 3array .22array FF2 and 3 always cancel to each other .2arr506 FF 2array . 2+array O0- . array506 .array506506 . / Kests thin' yourself(

--.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 static int a.4)%.8)c.A1 static int 2arr,546.93a)3%:1 static int 2arr4546.93%)3c:1 int2 +2arr546-546.93arr,)3arr4:1 printf+QHd HdRtQ)2+2arr506-5,6) 2+2+22+arrO,-O,---1 : Choose all that apply* )$* 4 8 )+* 4 A )C* 8 4 )D* 8 A )E* one of the a%ove

Lutput ( >D?

Gxplanation(
Consider on the following expression* 2+2arr506-5,6 .2+23arr,-5,6 FFarr506 . 3arr, .2arr,5,6 FF2 and 3 always cancel to each other .23% .% .8

Consider on following expression* 2+2+22+arrO,-O,-. 2+2+2arr5,6O,-- FF2+arrO,- . arr5,6 . 2+2+23arr4O,-- FFarr5,6 . 3arr4 .2+2+arr4O,-- FF23arr4 . arr4 .2+arr45,6- FF2+arr4O,- . arr45,6 . 23c FFarr45,6 . 3c . c . A

-8.
!hat will %e output when you will execute following c code; CincludeDstdio(hE CincludeDmath(hE dou%le myfun+dou%le-1 void main+-9 dou%le+2array576-+dou%le-1 array506.exp1 array5,6.sMrt1 array546.myfun1 printf+QH(,fRtQ)+2array-++2array546++22+arrayO,--+8----1 : dou%le myfun+dou%le d-9 dP.,1 return d1 : Choose all that apply* )$* 7(/ )+* @(0 )C* 4(@ )D* Compilation error )E* one of the a%ove

Lutput ( >C?

Gxplanation(

array is array of pointer to such function which parameter is dou%le type data and return type is dou%le( Consider on following expression* +2array-++2array546-++22+arrayO,--+8--. +2array-++2array546-++2array5,6-+8--FF2+arrayO,- . array5,6 . +2array-++2array546-+sMrt+8---FFarray5,6 . address of sMrt function . +2array-++2array546-+4(000000--. +2array-+myfun+4(000000--FF array546 . address of myfunc function .+2array-+,(000000.array506+,(000000.exp+,(000000-

-B.
!hat will %e output when you will execute following c code; CincludeDstdio(hE typedef struct9 char 2name1 dou%le salary1 :&o%1 void main+-9 static &o% a.9Q#CSQ),/000(0:1 static &o% %.9Q$BMQ)4/000(0:1 static &o% c.9QGoogleQ)7/000(0:1 int x./1 &o% 2 arr576.93a)3%)3c:1 printf+QHs HfRtQ)+7)xEE/P8-52arr6-1 : dou%le myfun+dou%le d-9 dP.,1 return d1 : Choose all that apply* )$* #CS ,/000(000000 )+* $BM 4/000(000000 )C* Google 7/000(000000

Compilation error )E* one of the a%ove


)D*

Lutput ( >C?

Gxplanation(
+7)/EE/P8-52arr6 .+7)/EE/P8-52arr6 FFx./ . +7)/EE,-52arr6 FFP operator en&oy higher precedence than EE . +7)4-52arr6 FF/EE, . /F+4U,- . / F4 . 4 . 452arr6 FF$n c comma is also operator( . 2+4 O 2arr. 2+2arr O 4.2arr546 .2+3c- FFarr546 . 3c .c FF 2 and 3 always cancel to each other( So) printf+QHs HfRtQ)c-1 .E printf+QHs HfRtQ) QGoogleQ)7/000(0-1

-F.
!hat will %e output when you will execute following c code; CincludeDstdio(hE union group9 char xarr5465461 char yarr5861 :1 void main+-9 union group x.9WAW)WBW)WCW)WDW:1 printf+QHcQ)x(xarr5x(yarr546P>@65x(yarr576P >@6-1 : Choose all that apply* )$* A )+* B )C* C )D* D )E* Compilation error

Lutput ( >I?

Gxplanation(
$n union all mem%er varia%les share common memory space( So union mem%er varia%le) array xarray will loo' li'e* 9 9XAY)YBY:) 9XCY)YDY: : And union mem%er varia%le) array yarray will loo' li'e* 9 9XAY)YBY)YCY)YDY: : x(xarr5x(yarr546P>@65x(yarr576P>@6 . x(xarr5XCYP>@65XDYP>@6 . x(xarr5>@P>@65>AP>@6 FFASC$$ value of XCY is >@ and XDY is >A( x(xarr5065,6 .YBY

-*.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int a./)%.,0)c.,/1 int 2arr576.93a)3%)3c:1 printf+QHdQ)2arr52arr5,6PA6-1 : Choose all that apply* )$* / )+* ,0 )C* ,/ )D* Compilation error )E* one of the a%ove

Lutput ( >D?

Gxplanation(
Mem%er of an array cannot %e address of auto varia%le %ecause array gets memory at load time while auto varia%le gets memory at run time(

-;.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int arr56576.99,)4:)97)8)/:)9/::1 printf+QHd Hd HdQ)siNeof+arr-)arr506546)arr5,6 546-1 : Choose all that apply* )$* ,4 7 / )+* ,A 0 / )C* ,4 0 / )D* ,A 7 / )E* Compilation error

Lutput ( >I?

Gxplanation(
$f we will not write siNe of first mem%er of any array at the time of declaration then siNe of the first dimension is max elements in the initialiNation of array of that dimension( So) siNe of first dimension in a%ove Muestion is 7( So siNe of array . +siNe of int- 2 +total num%er of elements- . 4 2+727- . ,A Default initial value of rest elements are Nero( So a%ove array will loo' li'e* 9 9,)4)0: 97)8)/:) 9/)0)0: :

-3.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int xxx5,06.9/:1 printf+QHd HdQ)xxx5,6)xxx5?6-1 : Choose all that apply* )$* Gar%age Gar%age )+* 0 0 )C* null null )D* Compilation error )E* one of the a%ove

Lutput ( >I?

Gxplanation(
$f we initialiNe any array at the time of declaration the compiler will treat such array as static varia%le and its default value of uninitialiNed mem%er is Nero(

-1.
!hat will %e output when you will execute following c code; CincludeDstdio(hE Cdefine !!! P, enum 9"at)rat:1 void main+-9 int Dhoni56.94)W%W)0x7)0,00,)WRx,dW)WR,,,W)rat) !!!:1 int i1 for+i.01iDA1iOOprintf+Q HdQ)Dhoni5i6-1 : Choose all that apply* )$* 4 ?A 8 /,7 4A @7 , P, )+* 4 ?A 8 /0@ 4? @7 4 P,

4 ?? 7 /,7 4? @7 4 P, )D* 4 ?A 7 /,7 4? @7 , P, )E* Compilation error


)C*

Lutput ( >D?

Gxplanation(
Dhoni506.4 Dhoni5,6.Y%Y .?A FFASC$$ value of character X%Y is ?A( Dhoni546. 0x7 . 7 FF0x represents hexadecimal num%er( Decimal value of hexadecimal 7 is also 7( Dhoni576.0,00, . /,7 FF um%er %egins with 0 represents octal num%er( Dhoni586 . XRx,dY . 4? FFYRx,dY is hexadecimal character constant( Dhoni5/6 . XR,,,Y . @7 FFYR,,,Y is octal character constant( Dhoni5>6 .rat . , FFrat is enum constant Dhoni5@6 . !!! . P, FF!!! is macro constant(

-N.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 long dou%le a1 signed char %1 int arr5siNeof+\aO%-61 printf+QHdQ)siNeof+arr--1 : Choose all that apply* )$* ,> )+* 8 )C* 4 )D* Compilation error )E* one of the a%ove

Lutput ( >I?

Gxplanation(

SiNe of data type in #UKBJ C 7(0 compiler is* S( ( Data type SiNe+$n %yte, char , 4 int 4 7 dou%le A Consider on the expression* \a O % \ Jperator always return Nero if a is nonPNero num%er other wisie ,( $n general we can say \ operator always returns an int type num%er( So \a O% .\ +Any dou%le type num%er- O Any character type num%er . Any integer type num%er O any character type num%er . Any integer type num%er ote* $n any expression lower type data is always automatically type casted into the higher data type( $n this case char data type is automatically type casted into the int type data( So siNeof +\a O%- . siNeof+Any int type num%er- . 4 So siNe of array arr is 4 and its data type is int( So siNeof+arr- . siNe of array 2 siNeof its data type . 42 4. 8

87.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 char array56.QAshfaM R0 ZayaniQ1 char 2str.QAshfaM R0 ZayaniQ1 printf+QHs HcRnQ)array)array546-1 printf+QHs HcRnQ)str)str546-1 printf+QHd HdRnQ)siNeof+array-)siNeof+str--1 : Choose all that apply*
)$*

AshfaM h AshfaM h ,> 4


)+*

AshfaM h AshfaM Zayani h ,> ,>

AshfaM y AshfaM h 4 4 )D* Compilation error )E* one of the a%ove


)C*

Lutput ( >'?

Gxplanation(
A character array 'eeps the each element of an assigned array %ut a character pointer always 'eeps the memory address of first element( As we 'now Hs in prints the characters of stream until it doesnYt any null character +XR0Y-( So first and second printf function will print same thing in the a%ove program( But siNe of array is total num%ers of its elements i(e( ,> %yte +including ending null character-( !hile siNe of any type of pointer is 4 %yte +near pointer-(

.tructure Juestions with explanation in c


Structure in c example

+M- !hat will %e output of following c code; void main+9 struct employee 9 unsigned id* A1

: Jutput* 407 , 47 !e can access the data mem%er in same way( How %it data is stored in the memory* Minimum siNe of structure which data mem%er in %it is two %yte i(e( ,> %it( #his is called word siNe of microprocessor( !ord siNe depends on microprocessor( #ur%o c is %ased on A0A> microprocessor which word siNe is two %yte( Bits are filed in from right to left direction A %it for id), %it for sex and @ %it for age( +M- !hat will %e output of following c code; void main+9 struct %itfield 9 unsigned a*/1 unsigned c*/1 unsigned %*>1 :%it1 char 2p1 struct %itfield 2ptr)%it,.9,)7)7:1 p.3%it,1 pOO1 clrscr+-1 printf+QHdQ)2p-1 getch+-1 : Jutput* ,4 <xplanation* Binary value of a., is 0000, +in / %itBinary value of %.7 is 000,, +in / %itBinary value of c.7 is 0000,, +in > %it-

unsigned sex*,1 unsigned age*@1 :1 struct employee emp,.9407),)47:1 clrscr+-1 printf+QHdRtHdRtHdQ)emp,(id)emp,(sex)emp,(age-1 getch+-1

$n memory it is represented as* [et address of %it, is /00 which initialiNe to char pointer p( Since can is one %yte data type so pOO will %e /0,( 2p means content of memory location /0, which is +0000,,00- and its %inary eMuivalent is ,4( Hence output is ,4( +M- !hat will %e output of following c code; void main+9 struct %itfield 9 signed int a*71 unsigned int %*,71 unsigned int c*,1 :1 struct %itfield %it,.94),8),:1 clrscr+-1 printf+QHdQ)siNeof+%it,--1 getch+-1 : Jutput* 8 +M- !hat will %e output of following c code; void main+9 struct %itfield 9 unsigned a*71 char %1 unsigned c*/1 int d1 :%it1 clrscr+-1 printf+QHdQ)siNeof+%it--1 getch+-1 : Jutput* / ote* +Actual output will > due to slac' %yte )So Before executing this program first go to option menu then compiler then code generation then select word alignment then press JZ-

+M- !hat will %e output of following c code; void main+9 struct field 9 int a1 char %1 :%it1 struct field %it,.9/)WAW:1 char 2p.3%it,1 2p.8/1 clrscr+-1 printf+QRnHdQ)%it,(a-1 getch+-1 : Jutput* 8/ esting of structure* esting of structure is possi%le i(e( we can declare a structure within another structure %ut it is necessary inner structure must declares structure varia%le otherwise we can not access the data mem%er of inner structure( <xample* void main+9 struct world 9 int a1 char %1 struct india 9 char c1 float d1 :p1 :1 struct world st .9,)WAW)WiW),(A:1 clrscr+-1 printf+QHdRtHcRtHcRt HfQ)st(a)st(%)st(p(c)st(p(d-1 getch+-1

: Jutput* , A $ ,(A00000 +M- !hat will %e output of following c code; void main+9 struct india 9 char c1 float d1 :1 struct world 9 int a5761 char %1 struct india orissa1 :1 struct world st .99,)4)7:)WPW)WMW),(8:1 clrscr+-1 printf+QHdRtHcRtHcRt HfQ)st(a5,6)st(%)st(orissa(c)st(orissa(d-1 getch+-1 : Jutput* 4 p M ,(800000

.witch Case Xuestion %echnical Juestions in c


C programming explanation technical Muestions and answers with

-.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int chec'.41 switch+chec'-9 case ,* printf+QD(!(SteynQ-1

case 4* printf+Q M(G(bohnsonQ-1 case 7* printf+Q Mohammad AsifQ-1 default* printf+Q M(MuralidaranQ-1

: Choose all that apply* M(G(bohnson )+* M(Muralidaran )C* M(G(bohnson Mohammad Asif M(Muralidaran )D* Compilation error )E* one of the a%ove
)$*

Lutput ( >C?

G x p l a n a t i o n (
$f we will not use %rea' 'eyword in each case the program control will come in each case after the case witch satisfy the switch condition(

8.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int movie.,1 switch+movieDD4Omovie-9 default*printf+Q7 $diotsQ-1 case 8* printf+Q Gha&iniQ-1 case /* printf+Q ZrrishQ-1 case A* printf+Q KaceQ-1 : : Choose all that apply* )$* 7 $diots Gha&ini Zrrish Kace )+* Kace )C* Zrrish )D* Gha&ini Zrrish Kace )E* Compilation error

Lutput ( >I?

G x p l a n a t i o n (
!e can write case statement in any order including the default case( #hat default case may %e first case) last case or in %etween the any case in the switch case statement(

B.
!hat will %e output when you will execute following c code; CincludeDstdio(hE Cdefine [ ,0 void main+-9 auto money.,01 switch+money)money24-9 case [* printf+Q!illianQ-1 %rea'1 case [24*printf+Q!arrenQ-1 %rea'1 case [27*printf+QCarlosQ-1 %rea'1 default* printf+Q[awrenceQ-1 case [28*printf+Q$nMvarQ-1 %rea'1 : : Choose all that apply* !illian )+* !arren )C* [awrence $nMvar )D* Compilation error* Misplaced default )E* one of the a%ove
)$*

Lutput ( >I?

G x p l a n a t i o n (
$n c comma is also precedence( So if x . +a ) %-1 operator which en&oy least

#hen x . % ote* Case expression can %e macro constant(

F.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int const S.01 switch+/F8F7-9 case S* printf+QClintonQ-1 %rea'1 case SO,*printf+QGandhiQ-1 %rea'1 case SO4*printf+QGatesQ-1 %rea'1 default* printf+QBrownQ-1 : : Choose all that apply* Clinton )+* Gandhi )C* Gates )D* Brown )E* Compilation error
)$*

Lutput ( >G?

G x p l a n a t i o n (
Case expression cannot %e constant varia%le(

*.
!hat will %e output when you will execute following c code; CincludeDstdio(hE enum actor9 +ean,enn./) -l,a"ino.P4) .ary/ld%an)

:1 void main+-9 enum actor a.01 switch+a-9 case +ean,enn*

0d1orton

printf+QZevin SpaceyQ-1 %rea'1 case -l,a"ino* printf+QPaul GiamattiQ-1 %rea'1 case .ary/ld%an*printf+QDonald ShuterlandQ-1 %rea'1 case 0d1orton* printf+Qbohnny DeppQ-1 : : Choose all that apply* Zevin Spacey )+* Paul Giamatti )C* Donald Shuterland )D* bohnny Depp )E* Compilation error
)$*

Lutput ( >D?

G x p l a n a t i o n (
Default value of enum constant GaryJldman . P4 O, . P, And default value of enum constant <d orton . P, O , . 0 ote* Case expression can %e enum constant(

;.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 switch+2+,OQABQ QCDQO,--9 case WAW*printf+QPulp "ictionQ-1 %rea'1

case WBW*printf+Q,4 Angry ManQ-1 %rea'1 case WCW*printf+QCasa%anceQ-1 %rea'1 case WDW*printf+QBlood DiamondQ-1

: Choose all that apply* Pulp "iction )+* ,4 Angry Man )C* Casa%ance )D* Blood Diamond )E* Compilation error
)$*

Lutput ( >C?

G x p l a n a t i o n (
Consider on the expression* 2+,OQABQ QCDQO,. 2+4OQABQ QCDQ. 2+4OQABCDQ.2+QCDQ.WCW ote* Case expression can %e character constant(

3.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 char 2str.QJ <Q strOO1 switch+str-9 case QJ <Q*printf+QBraNilQ-1 %rea'1 case Q <Q* printf+Q#oy storyQ-1 %rea'1 case Q Q* printf+QHis Girl "ridayQ-1

%rea'1 case Q<Q* printf+QCasino KoyaleQ-1 : Choose all that apply* BraNil )+* #oy story )C* His Girl "riday )D* Casino Koyale )E* Compilation error
)$*

Lutput ( >G?

G x p l a n a t i o n (
Case expression cannot %e string constant(

1.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 switch+/TT4T,-9 case 734*printf+QAnatomy of a MurderQ-1 %rea'1 case PV,,*printf+QPlanet of ApesQ-1 %rea'1 case >P7DD4*printf+Q#he conversationQ-1 %rea'1 case /E./*printf+QShaun of the DeadQ-1 : : Choose all that apply* Anatomy of a Murder )+* Planet of Apes )C* #he conversation )D* Shaun of the Dead )E* Compilation error
)$*

Lutput ( >G?

G x p l a n a t i o n (
Consider on the expression* /TT4T, ./TT +4T,- FFBitwise or has higher precedence ./TT7 ., ow) value of each case expression* 734 . 4 PV,, . P+P,4- .,4 >P7DD4 . 7 DD4 . ,4 /E./ . , case PV,, and case >P7DD4 have same constant expression i(e( case ,4 $n c duplicate case is not possi%le(

N.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 switch+>-9 case >(0f*printf+QSanga''araQ-1 %rea'1 case >(0* printf+QSehwagQ-1 %rea'1 case >(0[*printf+QSteynQ-1 %rea'1 default* printf+QSmithQ-1 : : Choose all that apply* Sanga''ara )+* Sehwag )C* Steyn )D* Smith )E* Compilation error
)$*

Lutput ( >G?

G x p l a n a t i o n (
Case expression must %e integral constant expression( $f it is not integer then it is automatically type casted into integer value( so( +int->(0f . > +int->(0 . > +int->(0[ . > $n c duplicate case is not possi%le(

-7.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 switch+0S0-9 case U[[*printf+Q#hierry HenryQ-1 %rea'1 case WR0W*printf+QSteven GerrendQ-1 %rea'1 case 0* printf+QZa'aQ-1 %rea'1 default* printf+QMichael Ballac'Q-1 : : Choose all that apply* #hierry Henry )+* Steven Gerrend )C* Za'a )D* Michael Ballac' )E* Compilation error
)$*

Lutput ( >G?

G x p l a n a t i o n (
Macro constant U[[ has %e defined as 0 in stdio(h ASC$$ value of character constant WR0W is 0 As we duplicate case is not possi%le in c(

--.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 switch+/F42>O7(0-9 case 7*printf+QDavid Bec'hamQ-1 %rea'1 case ,/*printf+QKonaldinhoQ-1 %rea'1 case 0*printf+Q[ionel MessiQ-1 %rea'1 default*printf+QKonaldoQ-1 : : Choose all that apply* David Bec'ham )+* Konaldinho )C* [ionel Messi )D* Konaldo )E* Compilation error
)$*

Lutput ( >G?

G x p l a n a t i o n (
Consider on the expression* /F42>O7(0 .42>O7(0 .,4 O 7(0 .,/(0 $n c switch expression must return an integer value( $t cannot %e float) dou%le or long dou%le

-8.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9

unsigned char c.4A01 switch+c-9 printf+QStartRtQ-1 case 4A0*printf+QDavid Bec'hamRtQ-1 case 48* printf+QKonaldinhoRtQ-1 default* printf+QKonaldoRtQ-1 printf+Q<ndQ-1 : : Choose all that apply* )$* Start David Bec'ham Konaldinho Konaldo <nd )+* Start David Bec'ham Konaldinho Konaldo )C* Start Konaldinho Konaldo <nd )D* Konaldinho Konaldo <nd )E* Compilation error

Lutput ( >D?

G x p l a n a t i o n (
4A0 is %eyond the range of unsigned char( $ts corresponding cyclic value is* 48 $n c switch case statement program control always move from the case which satisfy the switch condition and end with either %rea' 'eyword) terminating: or any null character which will come first(

-B.
!hat will %e output when you will execute following c code; CincludeDstdio(hE Cdefine #KU< , void main+-9 switch+#KU<-9 printf+Qctechnotips(%logspot(comQ-1 : : Choose all that apply*

ctechnotips(%logspot(com )+* $t will print nothing )C* Kuntime error )D* Compilation error )E* one of the a%ove
)$*

Lutput ( >I?

G x p l a n a t i o n (
$n c it is possi%le a switch case statement without any case %ut it is meaning less(

-F.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 static int i1 int &.,1 int arr5/6.9,)4)7)8:1 switch+arr5&6-9 case ,* iOO1%rea'1 case 4* iO.41&.71continue1 case 7* iH.41&.81continue1 default* PPi1 : printf+QHdQ)i-1 : Choose all that apply* 0 )+* , )C* 4 )D* Compilation error )E* one of the a%ove
)$*

Lutput ( >D?

G x p l a n a t i o n (

!e cannot use continue 'eyword in switch case( $t is part loop(

-*.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 static int i1 int &1 for+&.01&D./1&O.4switch+&-9 case ,* iOO1%rea'1 case 4* iO.41 case 8* iH.41&.P,1continue1 default* PPi1continue1 : printf+QHdQ)i-1 : Choose all that apply* 0 )+* , )C* 4 )D* Compilation error )E* one of the a%ove
)$*

Lutput ( >'?

G x p l a n a t i o n (
$n first iteration of for loop* & . 0 So) control will come to default) i . P, Due to continue 'eyword program control will move to %eginning of for loop $n second iteration of for loop* & .4 So) control will come to case 4) iO.4

i . iO4 . P, O4 ., #hen come to case 8) iH.4 i . iH4 . ,H4 . , &. P, Due to continue 'eyword program control will move to %eginning of for loop $n third iteration of for loop* & . P, O4 ., So) control will come to case , i . 4 $n the fourth iteration of for loop* & . ,O 4 .7 So) control will come to default) so i . , $n the fifth iteration of for loop* & . 7 O 4 ./ So) control will come to default) so i . 0 $n the sixth iteration of for loop* & . / O 4 .@ Since loop condition is false( So control will come out of the for loop(

-;.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int x.71 while+,-9 switch+x-9 case /F4* xO.xOOOx1 case 7H8* xO.xPPPx1continue1 case 7E.7* xO.\\\x1%rea'1 case /330*xO.VVVx1continue1 default* xO.PxPP1 : %rea'1 : printf+QHdQ)x-1

: Choose all that apply* 7 )+* P, )C* / )D* Compilation error )E* one of the a%ove
)$*

Lutput ( >I?

G x p l a n a t i o n (
#hin' yourself(

-3.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 char 2str.Qctechnotips(%logspot(comQ1 int a.41 switch+WAW-9 case ?@* switch+?@-9 default* strO.,1 : case >/* switch+?@-9 case WAW*strO.41 case WaW*strO.81 : default* for+1a1aPPstrO.A1 : printf+QHsQ)str-1 : Choose all that apply* )$* ctechnotips(%logspot(com )+* %logspot(com

(com )D* Compilation error )E* one of the a%ove


)C*

Lutput ( >C?

G x p l a n a t i o n (
ASC$$ value of the character constant WAW is >/ and WaW is ?@ esting of switch case is possi%le in c( "or loop condition in default case of switch %ecome false when varia%le QaQ %ecome 0 +Nero- value(

-1.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 switch+4-9 case ,[*printf+Q oQ-1 case 4[*printf+QHsQ)Q$Q-1 goto [ove1 case 7[*printf+QPleaseQ-1 case 8[*[ove*printf+QHiQ-1 : : Choose all that apply* $ )+* $PleaseHi )C* $Hi )D* Compilation error )E* one of the a%ove
)$*

Lutput ( >C?

G x p l a n a t i o n (
$t is possi%le to write la%el of goto statement in the case of switch case statement(

-N.

!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int a./1 a.aE.81 switch+4-9 case 0*int a.A1 case ,*int a.,01 case 4*OOa1 case 7*printf+QHdQ)a-1 : : Choose all that apply* A )+* ,, )C* ,0 )D* Compilation error )E* one of the a%ove
)$*

Lutput ( >G?

G x p l a n a t i o n (
!e can not declare any varia%le in any case of switch case statement(

87.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int a.7)%.41 a.a..%..01 switch+,-9 a.aO,01 : siNeof+aOO-1 printf+QHdQ)a-1 :

Choose all that apply* ,0 )+* ,, )C* ,4 )D* , )E* Compilation error
)$*

Lutput ( >D?

G x p l a n a t i o n (
Consider on the expression* a.a..%..01 a.+a..%-..01 FFSince associate is right to left a .+7..4-..0 a.0..0 a., switch case will not affect the value of varia%le a( Also siNeof operator doesnWt affect the value of the any varia%le

\ariable naming rule Juestions in c


"ollowing Muestion are %ased on varia%le naming rules in c( $f you have any dou%t in the varia%le naming rules you can as' here( 6ules for identifiers in c language -.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 int goto./1 printf+QHdQ)goto-1 return 01 :
op of (orm )$* /

)+* ,, )C* ,, )D* Compilation error )E* one of these Correct Lption is ( >D? Gxplanation(

$nvalid varia%le name( goto is 'eyword in c( varia%le name cannot %e any 'eyword of c language(
+ottom of (orm
8.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 long int ,a./l1 printf+QHldQ),a-1 return 01 :
op of (orm )$* / )+* /, )C* > )D* Compilation error )E* one of these Correct Lption is ( >D? Gxplanation(

$nvalid varia%le name( =aria%le name must star from either alpha%et or underscore(
+ottom of (orm
B.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 int ]./1 int ]].,01 int ]]]1

]]].]O]]1 printf+QHiQ)]]]-1 return 01

op of (orm )$* / )+* ,0 )C* ,/ )D* Compilation error )E* one of these +ottom of (orm Correct Lption is ( >C?Gxplanation(

=aria%le name can have only underscore(


F.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 int maxPval.,001 int minPval.,01 int avgPval1 avgPval . maxPval O minPval F 41 printf+QHdQ)avgPval-1 return 01 :
op of (orm )$* // )+* ,0/ )C*

>0 )D* Compilation error )E* one of these


Correct Lption is ( >D? Gxplanation(

!e cannot use special character _ in the varia%le name(


+ottom of (orm
*.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 int class.,/01 int pu%lic.4/1 int private.701 class . class EE private P pu%lic1 printf+QHdQ)class-1 return 01 :
op of (orm )$* , )+* 4 )C* 8 )D* Compilation error )E* one of these Correct Lption is ( >C? Gxplanation(

=aria%le name can %e 'eyword of cOO(


+ottom of (orm
;.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 inta%cdefghi&'lmnopMrstuvwxyN,478/>@A?.,01 int a%cdefghi&'lmnopMrstuvwxyN,478/>.801 printf+QHdQ)a%cdefghi&'lmnopMrstuvwxyN,478/>-1 return 01 :
op of (orm

)$* ,0 )+* 80 )C* /0 )D* Compilation error )E* one of these Correct Lption is ( >D? Gxplanation(

Jnly first 74 characters are significant in varia%le name( So compiler will show error* Multiple declaration of identifier a%cdefghi&'lmnopMrstuvwxyN,478/>(
+ottom of (orm
3.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 register xyN],47.?,1 auto pMr],47.??,1 const ],a,].pMr],47OVxyN],471 printf+QHdQ)],a,]-1 return 01 :
op of (orm )$* ?00 )+* ??? )C* A?? )D* Compilation error )E* one of these Correct Lption is ( >C? Gxplanation(

=aria%le name can have digits(


+ottom of (orm
1.

!hat will %e output of the following c program;

CincludeDstdio(hE int main+-9 int ]]SMA[[]] . ,,1 int y1 y. ]]SMA[[]] D /1 printf+QHdQ)y-1 return 01 :
op of (orm )$* ,, )+* / )C* 0 )D* Compilation error )E* one of these Correct Lption is ( >D? Gxplanation(

=aria%le name cannot %e glo%al identifier(


+ottom of (orm
N.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 int ]]B$G]] . 741 int y1 y. ]]B$G]] 33 A1 printf+QHdQ)y-1 return 01 :
op of (orm )$*

74 )+* A )C* , )D* Compilation error )E* one of these

Correct Lption is ( >C? Gxplanation(

=aria%le name can %e in the format* ]] AM<]]( But it is %ad practice since this format is used for glo%al identifiers(
+ottom of (orm
-7.

!hat will %e output of the following c program; CincludeDstdio(hE static num./1 int num1 extern int num1 int main+-9 printf+QHdQ)num-1 return 01 :
op of (orm )$* / )+* ,0 )C* 0 )D* Compilation error )E* one of these Correct Lption is ( >'? Gxplanation(

#wo or more glo%al varia%les can have same name %ut we can initialiNe only one of them(
+ottom of (orm
--.

!hat will %e output of the following c program; CincludeDstdio(hE static num./1 extern int num1 int main+-9 printf+QHdQ)num-1 return 01

: int num .4/1


op of (orm )$*

0 )+* / )C* 4/ )D* Compilation error )E* one of these


Correct Lption is ( >D? Gxplanation(

#wo or more glo%al varia%les can have same name %ut we can initialiNe only one of them(
+ottom of (orm
-8.

!hat will %e output of the following c program; CincludeDstdio(hE static num1 int main+-9 printf+QHdQ)num-1 return 01 : int num .4/1
op of (orm )$* 0 )+* , )C* 4/ )D* Compilation error )E* one of these Correct Lption is ( >C? Gxplanation(

#wo or more glo%al varia%les can have same name %ut we can initialiNe only one of them(
+ottom of (orm

-B.

!hat will %e output of the following c program; CincludeDstdio(hE int xyN.,01 int main+-9 int xyN.401 printf+QHdQ)xyN-1 return 01 :
op of (orm )$* ,0 )+* 40 )C* 70 )D* Compilation error )E* one of these Correct Lption is ( >I? Gxplanation(

#wo varia%les can have same name in different scope(


+ottom of (orm
-F.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 int xyN.401 int xyN1 printf+QHdQ)xyN-1 return 01 :
op of (orm )$* 40 )+*

0 )C* Gar%age

)D* Compilation error )E* one of these Correct Lption is ( >D? Gxplanation(

#wo local varia%les cannot have same name in same scope(


+ottom of (orm
-*.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 int xyN.4019 int xyN.801 : printf+QHdQ)xyN-1 return 01 :
op of (orm )$* 40 )+* )C*

80

0 )D* Compilation error )E* one of these


Correct Lption is ( >'? Gxplanation(

#wo varia%les can have same name in different scope(


+ottom of (orm
-;.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 int main . A01

printf+QHdQ)main-1 return 01 :
op of (orm )$* A0 )+* )C*

Gar%age value )D* Compilation error )E* one of these


Correct Lption is ( >'? Gxplanation(

=aria%le name can %e main(


+ottom of (orm
-3.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 struct a9 int a1 :1 struct a %.9,0:1 printf+QHdQ)%(a-1 return 01 :
op of (orm )$* 0 )+*

,0 )C* Gar%age value )D* Compilation error )E* one of these


Correct Lption is ( >I? Gxplanation(

#wo varia%les can have same name in different scope(


+ottom of (orm
-1.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 int ABC.,01 printf+QHdQ)a%c-1 return 01 :
op of (orm )$* ,0 )+* 0 )C* / )D* Compilation error )E* one of these Correct Lption is ( >D? Gxplanation(

=aria%le name is case sensitive(


+ottom of (orm
-N.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 int printf.,41 printf+QHdQ)printf-1 return 01 :
op of (orm )$* ,4 )+*

0 )C* /

)D* Compilation error )E* one of these Correct Lption is ( >D? Gxplanation(

=aria%le name cannot %e pre defined function of included header file(


+ottom of (orm
87.

!hat will %e output of the following c program; CincludeDstdio(hE int main+-9 int <J".,41 printf+QHdQ)<J"-1 return 01 :
op of (orm )$* ,4 )+*

0 )C* / )D* Compilation error )E* one of these


Correct Lption is ( >D? Gxplanation(

=aria%le name cannot %e pre defined function of included header file(


+ottom of (orm
Category ( Xuestion and 'nswer

C operator Juestion with answer

+,!hat will %e output of the following program; CincludeDstdio(hE

int main+-9 float a.0(@1 if+aD0(@-9 printf+QCQ-1 : else9 printf+QCOOQ-1 : return 01 :


EXPLANATION

Jutput* #ur%o COO 7(0* c #ur%o C OO8(/* c [inux GCC* c =isual COO* c <xplanation* 0(@ is dou%le constant +Default-( $ts %inary value is written in >8 %it( Binary value of 0(@ . +0(,0,, 00,, 00,, 00,, 00,, 00,, 00,, 00,, 00,, 00,, 00,, ow here varia%le a is a floating point varia%le while 0(@ is dou%le constant( So varia%le a will contain only 74 %it value i(e( a . 0(,0,, 00,, 00,, 00,, 00,, 00,, 00,, 00,, while 0(@ . 0(,0,, 00,, 00,, 00,, 00,, 00,, 00,, 00,, 00,, 00,, 00,,(((( $t is o%vious a D 0(@ +4!hat will %e output of the following program;

CincludeDstdio(hE int main+-9 int i./)&1 &.OOiOOOiOOOi1 printf+QHd HdQ)i)&-1 return 01 :


EXPLANATION

Jutput* #ur%o COO 7(0* A 48 #ur%o C OO8(/* Compilation error [inux GCC* Compilation error =isual COO* Compilation error <xplanation* Kule *P OO is pre increment operator so in any arithmetic expression it first increment the value of varia%le %y one in whole expression then starts assigning the final value of varia%le in the expression( Compiler will treat this expression & . OOiOOOiOO Oi1 as i . OOi O OOi O OOi1 $nitial value of i . / due to three pre increment operator final value of i.A( ow final value of i i(e( A will assigned to each varia%le as shown in the following figure*

So) &.AOAOA

&.48 and i.A +7!hat will %e output of the following program; CincludeDstdio(hE int main+-9 int i.,1 i.4O42iOO1 printf+QHdQ)i-1 return 01 :
EXPLANATION

Jutput* #ur%o COO 7(0* / #ur%o C OO8(/* / [inux GCC* / =isual COO* / <xplanation* iOO i(e( when postfix increment operator is used any expression the it first assign the its value in the expression the it increments the value of varia%le %y one( So) i . 4 O 4 2 , i . 8 ow i will %e incremented %y one so i . 8 O , . / +8!hat will %e output of the following program; CincludeDstdio(hE int main+-9 int a.4)%.@)c.,01 c.a..%1 printf+QHdQ)c-1

return 01

EXPLANATION

Jutput* #ur%o COO 7(0* 0 #ur%o C OO8(/* 0 [inux GCC* 0 =isual COO* 0 <xplanation* .. is relational operator which returns only two values( 0* $f a .. % is false ,* $f a .. % is true Since a.4 %.@ So) a .. % is false hence %.0 +/!hat will %e output of the following program; CincludeDstdio(hE void main+-9 int x1 x.,0)40)701 printf+QHdQ)x-1 return 01 :
EXPLANATION

Jutput* #ur%o COO 7(0* ,0 #ur%o C OO8(/* ,0

[inux GCC* ,0 =isual COO* ,0 <xplanation * Precedence ta%le* Jperator Precedence . More than ) ) [east

Associative Kight to left [eft to right

Since assignment operator +.- has more precedence than comma operator (So . operator will %e evaluated first than comma operator( $n the following expression x . ,0) 40) 70 "irst ,0 will %e assigned to x then comma operator will %e evaluated( +>!hat will %e output of the following program; CincludeDstdio(hE int main+-9 int a.0)%.,01 if+a.0-9 printf+QtrueQ-1 : else9 printf+QfalseQ-1 : return 01 :
EXPLANATION

Jutput* #ur%o COO 7(0* false #ur%o C OO8(/* false

[inux GCC* false =isual COO* false <xplanation* As we 'now . is assignment operator not relation operator( So) a . 0 means Nero will assigned to varia%le a( $n c Nero represent false and any nonP Nero num%er represents true( So) if+0- means condition is always false hence else part will execute( +@!hat will %e output of the following program; CincludeDstdio(hE int main+-9 int a1 a.0,/ O 0x@, O/1 printf+QHdQ)a-1 return 01 :
EXPLANATION

Jutput* #ur%o COO 7(0* ,7, #ur%o C OO8(/* ,7, [inux GCC* ,7, =isual COO* ,7, <xplanation* 0,/ is octal num%er its decimal eMuivalent is . / 2 A U 0 O , 2 A U , . / O A . ,7 0x@, is hexadecimal num%er +0x is sym%ol of hexadecimal- its decimal eMuivalent is . , 2 ,> U 0

O @ 2 ,> U , . , O ,,4 . ,,7 So) a . ,7 O ,,7 O / . ,7, +A!hat will %e output of the following program; CincludeDstdio(hE int main+-9 printf+QHd Hd HdQ)siNeof+7(,8-)siNeof+7(,8f-)siNeof+7(,8[--1 return 01 :
EXPLANATION

Jutput* #ur%o COO 7(0* A 8 ,0 #ur%o C OO8(/* A 8 ,0 [inux GCC* A 8 ,4 =isual COO* A 8 A <xplanation* 7(,8f is floating point constant( $ts siNe is 8 %yte( 7(,8 is dou%le constant +default-( $ts siNe is A %yte( 7(,8[ is long dou%le constant( $ts siNe is ,0 %yte( siNeof+- operator always return the siNe of data type which is written inside the+-( $t is 'eyword( +?!hat will %e output of the following program; CincludeDstdio(hE int main+-9 int x.,00)y.40)N./1 printf+QHd Hd HdQ-1 return 01 :

EXPLANATION

Jutput* #ur%o COO 7(0* / 40 ,00 #ur%o C OO8(/* / 40 ,00 [inux GCC* Gar%age values =isual COO* / ,00 40 By default x) y) N are auto type data which are stored in stac' in memory( Stac' is [$"J data structure( So in stac' first stores ,00 then 40 then / and program counter will point top stac' i(e( /( Default value of Hd in printf is data which is present in stac'( So output is revere order of declaration( So output will %e / 40 ,00( +,0!hat will %e output of the following program; CincludeDstdio(hE int main+-9 int a.41 a.aOO O VOOa1 printf+QHdQ)a-1 return 01 :
EXPLANATION

Jutput* #ur%o COO 7(0* P, #ur%o C OO8(/* 0 [inux GCC* 0 =isual COO* 0

<xplanation* Same theory as Muestion +4- and +,7-( +,,!hat will %e output of the following program; CincludeDstdio(hE int main+-9 int a1 a.siNeof+\/(>-1 printf+QHdQ)a-1 return 01 :
EXPLANATION

Jutput* #ur%o COO 7(0* 4 #ur%o C OO8(/* 4 [inux GCC* 8 =isual COO* 8
<xplanation* \ is negation operator it return either integer 0 or ,( \ Any operand . 0 if operand is non Nero( \ Any operand . , if operand is Nero( So) \/(> . 0 Since 0 is integer num%er and siNe of integer data type is two %yte( +,4!hat will %e output of the following program; CincludeDstdio(hE int main+-9 float a1 +int-a. 8/1 printf+QHd)a-1 return 01 :

EXPLANATION

Jutput* #ur%o COO 7(0* Compilation error #ur%o C OO8(/* Compilation error [inux GCC* Compilation error =isual COO* Compilation error
<xplanation* After performing any operation on operand it always return some constant value( +int- i(e( type casting operator is not exception for this( +int- a will return one constant value and we cannot assign any constant value to another constant value in c( +int-a . 8/1 is eMuivalent to 78/> . 8/ + Here 78/> in any gar%age value of int+a--( +,7!hat will %e output of the following program; CincludeDstdio(hE int main+-9 int i./1 int a.OOi O OOi O OOi1 printf+QHdQ)a-1 return 01 :
EXPLANATION

Jutput* #ur%o COO 7(0* 4, #ur%o C OO8(/* 4, [inux GCC* 44 =isual COO* 48 <xplanation*

Kule * OO +in OOi- is pre increment operator so in any arithmetic expression it first increment the value of varia%le %y one in whole eMuation up to %rea' point then start assigning the value of varia%le in the eMuation( #here are many %rea' point operators in( "or example* +,- Declaration statement( +4- 33 or operator( +7- Comma +)- operator etc( $n the following expression* int a.OOi O OOi O OOi1 Here %rea' point is due to declaration ($t %rea' after each increment i(e( +initial value of i./after first increment value > assign to varia%le i then in next increment will occur and so on( So) a . > O @ O A1

Contol low Xuestions 5f else Juestions in c

- .

!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int a./)%.,0)c.,1 if+a33%Ec-9 printf+QctechnotipsQ-1 : else9 %rea'1 : : Choose all that apply*

)$* )+* )C* )D* )E*

ctechnotips $t will print nothing Kun time error Compilation error one of the a%ove

'nswer ( >D? G x p l a n a t i o n (
Zeyword %rea' is not syntactical part of ifPelse statement( So we cannot use %rea' 'eyword in ifP else statement( #his 'eyword can %e use in case of loop or switch case statement( Hence when you will compile a%ove code compiler will show an error message*2ispla"ed 3rea)( !hat will %e output when you will execute following c code; Cdefine PK$ # printf+QStar !arsQ-1printf+Q PsychoQ-1 CincludeDstdio(hE void main+-9 int x.,1 if+xPPPK$ # else printf+Q#he Shawshan' KedemptionQ-1 : Choose all that apply* )$* Stars !ars Psycho )+* #he Shawshan' Kedemption )C* !arning* Condition is always true )D* !arning* Condition is always false )E* Compilation error

8 .

'nswer ( >G? G x p l a n a t i o n (
PK$ # is macro constant( Macro PK$ # will %e replaced %y its defined statement &ust %efore the

actual compilation starts( A%ove code is converted as* void main+-9 int x.,1 if+xPPprintf+QStar !arsQ-1 printf+Q PsychoQ-1 else printf+Q#he Shawshan' KedemptionQ-1 : $f you are not using opening and closing curly %rac'et in if clause) then you can write only one statement in the if clause( So compiler will thin'* +iif+xPPprintf+QStar !arsQ-1 $t is if statement without any else( $t is o'( +iiprintf+Q PsychoQ-1 $t is a function call( $t is also o' +iiielse printf+Q#he Shawshan' KedemptionQ-1 Lou cannot write else clause without any if clause( $t is cause of compilation error( Hence compiler will show an error message*2ispla"ed else

B .

!hat will %e output when you will execute following c code; Cdefine #rue /../ CincludeDstdio(hE void main+-9 if+(00,P0(,fprintf+QDavid Bec'hamQ-1 else if+#rueprintf+QKonaldinhoQ-1 else printf+QCristiano KonaldoQ-1 :

Choose all that apply* )$* David Bec'ham )+* Konaldinho )C* Cristiano Konaldo )D* !arning* Condition is always true )E* !arning* Unreacha%le code

'nswer ( >'2D2G? G x p l a n a t i o n (

As we 'now in c Nero represents false and any nonP Nero num%er represents true( So in the a%ove code* +0(00, _ 0(,f- is not Nero so it represents true( So only if clause will execute and it will print* David Bec'ham on console( But it is %ad programming practice to write constant as a condition in if clause( Hence compiler will show a warning message*Condition is al4ays true Since condition is always true) so else clause will never execute( Program control cannot reach at else part( So compiler will show another warning message* 5nrea"ha3le "ode !hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int a.,001 if+aE,0printf+QM(S( DhoniQ-1 else if+aE40printf+QM(<(Z HusseyQ-1 else if+aE70printf+QA(B( de villiersQ-1 : Choose all that apply* )$* M(S( Dhoni )+* A(B( de villiers
)C*

F .

M(S Dhoni M(<(Z Hussey A(B( de =illiers Compilation error* More than one conditions are true one of the a%ove )E*
)D*

'nswer ( >'? G x p l a n a t i o n (

$n case of if _ if else _ if else ^ Statement if first if clause is true the compiler will never chec' rest of the if else clause and so on(

* .
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int x.P,)y.P,1 if+OOx.OOyprintf+QK(#( PontingQ-1 else printf+QC(H( GayleQ-1 : Choose all that apply* )$* K(# Ponting )+* C(H( Gayle

!arning* x and y are assigned a value that is never used )D* !arning* Condition is always true )E* Compilation error
)C*

'nswer ( >C2G? G x p l a n a t i o n (
Consider following statement* OOx.OOy As we 'now OO is pre increment operator in the a%ove statement( #his operator increments the value

of any integral varia%le %y one and return that value( After performing pre increments a%ove statement will %e* 0.0 $n C language it is illegal to assign a constant value to another constant( [eft side of . operator must %e a container i(e( a varia%le( So compiler will show an error message* 67alue re8uired $n c if you assign any value to varia%le %ut you donYt perform any operator or perform operation only using unary operator on the varia%le the complier will show a warning message* 'aria3le is assi!ned a 7alue that is ne7er !hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 if+siNeof+void-printf+QM( MuralilidaranQ-1 else printf+QHar%ha&an SinghQ-1 : Choose all that apply* )$* M( Muralilidaran )+* Har%ha&an Singh )C* !arning* Condition is always false )D* Compilation error one of the a%ove )E*

; .

'nswer ( >D? G x p l a n a t i o n (

$t illegal to find siNe of void data type using siNeof operator( Because siNe of void data type is meaning less(

3 .
!hat will %e output when you will execute following c code; CincludeDstdio(hE

void main+-9 int m./)n.,0)M.401 if+MFn2mprintf+Q!illiam else printf+Q !arren printf+Q Carlos : Choose all that apply* )$* !illiam Gates )+* !arren Buffet Carlos )C* Kun time error )D* Compilation error one of the a%ove )E*

GatesQ-1 BuffetQ-1 Slim HeluQ-1

Slim Helu

Consider the following expression* M F n 2 m $n this expression there are two operators( #hey are* F* Division operator 2* Multiplication operator Precedence and associate of each operator is as follow* Precedence Operator $ssociate ./, 0eft to right

'nswer ( >G? G x p l a n a t i o n (

Precedence of %oth operators is same( Hence associate will decide which operator will execute first( Since Associate is left to right( So F operator will execute then 2 operator will execute( . M F n 2 m . 40 F ,0 2 / . 4 2 / .,0 As we 'now in c Nero represents false and any nonP Nero num%er represents true( Since ,0 is nonP Nero

num%er so if clause will execute and print* !illiam Gates Since in else clause there is not any opening and closing curly %rac'et( So compiler will treat only one statement as a else part( Hence last statement i(e( printf+Q Carlos Slim HeluQ-1 is not part of ifPelse statement( So at the end compiler will also print* Carlos Slim Helu So output of a%ove code will %e* !illiam Gates Carlos Slim Helu !hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 if+\printf+QMu'esh Am%aniQ-if+printf+Q [a'ashmi MittalQ--1 : Choose all that apply* )$* Mu'esh Am%ani [a'ashmi Mittal )+* )C* $t will print nothing )D* Mu'esh Am%ani [a'ashmi Mittal )E* Compilation error* if statement without %ody

1 .

'nswer ( >'? G x p l a n a t i o n (

Keturn type of printf function is int( #his function return a integral value which is eMual to num%er of characters a printf function will print on console( "irst of all printf function will* Mu'esh Am%ani( Since it is printing ,7 character so it will return ,7( So) \printf+QMu'esh Am%aniQ. \,7 . 0 $n c language Nero represents false( So if+0- is false so next statement which inside the %ody of first if statement will not execute(

N .
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 if+QABCQ- printf+QBarac' J%amaRnQ-1 if+P,printf+QHu bintaoRnQ-1 if+(?4[- printf+Q icolas Sar'oNyRnQ-1 if+0printf+QBen Bernan'eRnQ-1 if+W!Wprintf+Q=ladimir PutinRnQ-1 : Choose all that apply*

)$* $t will print nothing )+* Barac' J%ama


Hu bintao icolas Sar'oNy =ladimir Putin

)C* Barac' J%ama


Hu bintao icolas Sar'oNy Ben Bernan'e =ladimir Putin

)D* Hu bintao
icolas Sar'oNy =ladimir Putin

)E* Compilation error

'nswer ( >I? G x p l a n a t i o n (

GABCI* $t is string constant and it will always return a nonPNero memory address( 0(?4[* $t is long dou%le constant(

X!Y* $t is character constant and its ASC$$ value is As we 'now in c language Nero represents false and any nonPNero num%er represents true( $n this program condition of first) second) third and fifth if statements are true(

-7.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 if+0xAif+0/4if+WRxe%Wif+WR0,4Wprintf+Q#om han'sQ-1 else1 else1 else1 else1 : Choose all that apply* )$* #om han's )+* Compilation error* Misplaced else )C* Compilation error* $f without any %ody )D* Compilation error* Undefined sym%ol )E* !arning* Condition is always true

'nswer ( >'2G? G x p l a n a t i o n (

oxA* $t is hexadecimal integer constant( 0/4* $t octal integer constant( XRxe%Y* $t is hexadecimal character constant( XR0,4Y* $t is octal character constant( As we 'now in c Nero represents false and any nonP Nero num%er represents true( All of the a%ove constants return a nonPNero value( So all if conditions in the a%ove program are true( $n c it is possi%le to write else clause without any %ody(

--.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int a.,01 if+printf+QHdQ)aE.,0-P,0for+11%rea'1 else1 : Choose all that apply* )$* $t will print nothing )+* 0 )C* , )D* Compilation error* Misplaced else )E* $nfinite loop

'nswer ( >C? G x p l a n a t i o n (

Keturn type of printf function is int( #his function return a integral value which is eMual to num%er of charcters printf function will print on console( Jperator E. will return , if %oth operands are either eMual or first operand is grater than second operand( So aE.,0 will return , since a is eMual to ,0(#hus printf function will print ,( Since this function is printing only one character so it will also return ,( So) printf+QHdQ)aE.,0- P ,0 . , P ,0 . P? Since P? is nonPNero num%er so if+P?- is true condition hence if clause will execute which contains an infinite loop %ut due to %rea' 'eyword it will come out of loop(

-8.

!hat will %e output when you will execute following c code;

CincludeDstdio(hE void main+-9 int a./)%.,01 if+OOaTTOO%printf+QHd HdQ)a)%-1 else printf+Qbohn #erryQ-1 : Choose all that apply* )$* / ,0 )+* > ,, )C* > ,0 )D* / ,, )E* bohn #erry

'nswer ( >C? G x p l a n a t i o n (

Consider the following expression* OOa TT OO% $n this expression TT is [ogical JK operator( #wo important properties of this operator are* Property ,* +<xpression,- TT +<xpression4TT operator returns 0 if and only if %oth expressions return a Nero otherwise it TT operator returns ,( Property 4* #o optimiNe the execution time there is rule) <xpression4 will only evaluate if and only if <xpression, return Nero( $n this program initial value of a is /( So OOa will %e >( Since OOa is returning a nonPNero so OO% will not execute and if condition will %e true and if clause will %e executed(

-B.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 static int i1

: Choose all that apply* )$* $t will print Memento at one time )+* $t will print Memento at three times )C* $t will print Memento at ten times )D* $t will print Memento at infinite times )E* Compilation error* Un'nown operator OOO

for+11if+iOOOQ#he MatrixQprintf+QMementoQ-1 else %rea'1

'nswer ( >D? G x p l a n a t i o n (
#hin' yourself

-F.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int x.,1 if+xPPprintf+Q#he GodfatherQ-1 PPx1 else printf+QHdQ)x-1 : Choose all that apply* )$* #he Godfather )+* , )C* 0 )D* Compilation error one of the a%ove )E*

'nswer ( >D? G x p l a n a t i o n (
$f you are not using 9 and : in if clause then you can write only one statement( Jtherwise it will cause of compilation error*2ispla"e else

-*.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 if+WR0W-1 else if+ U[[printf+QctechnotipsQ-1 else1 : Choose all that apply* )$* ctechnotips )+* $t will print nothing )C* !arning* Condition is always true )D* !arning* Unreacha%le code Compilation error* if statement without any )E* %ody

'nswer ( >I2D? G x p l a n a t i o n (

XR0Y is null character constant( $ts ASC$$ value is Nero( if+0- means false so program control will chec' it else if clause( U[[ is macro constant which has %een defined in stdio(h which also returns Nero(

-;.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int a./)%.,01 clrscr+-1 if+aDOOaTT%DOO%printf+QHd HdQ)a)%-1 else printf+QZPQ-1 : Choose all that apply* )$* / ,0

)+* )C* )D* )E*

> ,, > ,0 Compilation error ZP

Consider the following expression* aDOOaTT%DOO% $n the a%ove expression TT is logical JK operator( $t divides any expression in the su% expressions( $n this way we have two su% expressions* +,- aDOOa +4- %DOO% $n the expression* aD OOa #here are two operators( #here precedence and associate are* Precedence Operator $ssociate 3 11 4 2ight to left 0eft to right

'nswer ( >G? G x p l a n a t i o n (

"rom ta%le it is clear first OO operator will perform the operation then D operator( Jne important property of prePincrement +OOoperator is* $n any expression first prePincrement increments the value of varia%le then it assigns same final value of the varia%le to all that varia%les( So in the expression* a D OOa $nitial value of varia%le a is /( Step ,* $ncrement the value of varia%le a in whole expression( "inal value of a is >( Step 4* ow start assigning value to all a in the expression( After assigning > expression will %e* > D > Since condition is false (So second expression i(e( %DOO% will %e evaluated( Again ,, D ,, is false( So TT will operator will return Nero and else clause will execute(

-3.
!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int x.,)y.41 if+PPx 33 PPyprintf+Qx.Hd y.HdQ)x)y-1 else printf+QHd HdQ)x)y-1 : Choose all that apply* )$* , 4 )+* x., y.4 )C* 0 4 )D* x.0 y., )E* 0 ,

'nswer ( >C? G x p l a n a t i o n (

Consider the following expression* PPx 33 PPy $n this expression 33 is [ogical A D operator( #wo important properties of this operator are* Property ,* +<xpression,- 33 +<xpression433 operator returns , if and only if %oth expressions return a nonPNero value other wise it 33 operator returns 0( Property 4* #o optimiNe the execution time there is rule) <xpression4 will only evaluate if and only if <xpression, return a nonPNero value( $n this program initial value of x is ,( So _x will %e Nero( Since P_x is returning Nero so P_y will not execute and if condition will %e false( Hence else part will %e executed(

-1.

!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 signed int a.P,1 unsigned int %.P,u1 if+a..%printf+Q#he [ord of the KingsQ-1 else printf+QAmerican BeautyQ-1 : Choose all that apply* )$* #he [ord of the Kings )+* American Beauty
)C* Compilation error* Cannot compare signed

num%er with unsigned num%er )D* Compilation error* Undefined sym%ol P,u )E* !arning* $llegal operation

'nswer ( >'? G x p l a n a t i o n (
Kead following tutorial* Data type tutorial

!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 char c.4/>1 char 2ptr.Q[eonQ1 if+c..0while+\cif+2ptrOOprintf+QHOuQ)c-1 else %rea'1 : Choose all that apply* )$* O4/>O4/>O4/>O4/>

-N.

)+* )C* )D* )E*

0000 O0O0O0O0 $t will print O4/> at infinite times Compilation error

'nswer ( >C? G x p l a n a t i o n (

$n the a%ove program c is signed +default- char varia%le( Kange of signed char varia%le in #ur%o c is from P,4A to ,4@( But we are assigning 4/> which is %eyond the range of varia%le c( Hence varia%le c will store corresponding cyclic value according to following diagram*

Since 4/> is positive num%er move from Nero in cloc' wise direction( Lou will get final value of c is Nero( if+c..0$t is true since value of c is Nero(

egation operator i(e( \ is always return either Nero or one according to following rule*
\0 . , \+ onPNero num%er- . 0 So) \c . \0 ., As we 'now in c Nero represents false and any nonPNero num%er represents true( So while+\c- i(e( while+,- is always true( $n the a%ove program prt is character pointer( $t is pointing to first character of string G[eonI according to following diagram*

$n the a%ove figure value in circle represents ASC$$ value of corresponding character( $nitially 2ptr means X[Y( So 2ptr will return ASC$$ value of character constant X[Y i(e( @> if+2ptrOO- is eMuivalent to * if+X[Y- is eMuivalent to* if+@>- ( $t is true so in first iteration it will print O0( Due to OO operation in second iteration ptr will point to character constant XeY and so on( !hen ptr will point XR0Y i(e( null character ($t will return its ASC$$ value i(e( 0( So if+0- is false( Hence else part will execute(

87.

!hat will %e output when you will execute following c code; CincludeDstdio(hE void main+-9 int a.41 if+aPP)PPa)aprintf+Q#he Dalai [amaQ-1 else printf+Qbim KogersQ-1 : Choose all that apply* )$* #he Dalai [ama )+* bim Kogers )C* Kun time error

Compilation error* Multiple parameters in if statement one of the a%ove )E*


)D*

'nswer ( >I? G x p l a n a t i o n (
Consider the following expression* aPP ) PPa ) a $n c comma is %ehaves as separator as well as operator($n the a%ove expression comma is %ehaving as operator(Comma operator en&oy lest precedence in precedence ta%le andits associatively is left to right( So first of all left most comma operator will perform operation then right most comma will operator in the a%ove expression( After performing aPP * a will %e 4 After performing PPa * a will %e 0 a.0 As we 'now in c Nero represents false and any nonP Nero num%er represents true( Hence else part will execute(

C PL5N%G6 XUG.%5LN. C PL5N%G6 XUG.%5LN.


C pointers interview Muestions and answers
$t is freMuently as'ed technical o%&ective types multiple choice Muestions of placement in c programming language ote* [inux GCC compilers and =isual COO compiler doesnWt support far and huge pointers(

-5
!hat will %e output of following program; CincludeDstdio(hE int main+-9 int a . 7401 char 2ptr1 ptr .+ char 2-3a1 printf+QHd Q)2ptr-1 return 01 : )$* 4 )+* 740 )C* >8 )D* Compilation error )E* one of a%ove

Output : (C)

E " p l a n a t i o n !
#ur%o COO 7(0* >8 #ur%o C OO8(/* >8

[inux GCC* >8 =isual COO* >8 As we 'now int is two %yte data %yte while char is one %yte data %yte( char pointer can 'eep the address one %yte at time( Binary value of 740 is 0000000, 0,000000 +$n ,> %itMemory representation of int a . 740 is*

So ptr is pointing only first A %it which color is green and Decimal value is >8(

35
!hat will %e output of following program; CincludeDstdio(hE CincludeDconio(hE int main+-9 void +2p-+-1 int +2M-+-1 int +2r-+-1 p . clrscr1 M . getch1 r . puts1 +2p-+-1 +2r-+Qctechnotips(%logspot(comQ-1 +2M-+-1 return 01 :

)$* U[[ )+* ctechnotips(%logspot(com )C* c )D* Compilation error )E* one of a%ove

Output : (B)

E " p l a n a t i o n !
#ur%o COO 7(0* ctechnotips(%logspot(com #ur%o C OO8(/* ctechnotips(%logspot(com [inux GCC* Compilation error =isual COO* Compilation error p is pointer to function whose parameter is void and return type is also void( r and M is pointer to function whose parameter is void and return type is int ( So they can hold the address of such function(

65
!hat will %e output of following program; CincludeDstdio(hE int main+-9 int i . 71 int 2&1 int 22'1 &.3i1 '.3&1 printf+QHu Hu Hd Q)')2')22'-1 return 01 : )$* Address) Address) 7 )+* Address) 7) 7 )C* 7) 7) 7

)D* Compilation error )E* one of a%ove

Output : (A)
E"planation!

#ur%o COO 7(0* Address) Address) 7 #ur%o C OO8(/* Address) Address) Address [inux GCC* Address) Address) 7 =isual COO* Address) Address) 7 Memory representation

Here >048) A0A/) ?0?, is any ar%itrary address) it may %e different( =alue of ' is content of ' in memory which is A0A/ =alue of 2' means content of memory location which address ' 'eeps( ' 'eeps address A0A/ ( Content of at memory location A0A/ is >048 $n the same way 22' will eMual to 7( Short cut way to calculate* Kule* 2 and 3 always cancel to each other i(e( 23a . a So 2' . 2+3&- since ' . 3&

23& . & . >048 And 22' . 22+3&- . 2+23&- . 2& . 2+3i- . 23i . i . 7

!hat will %e output of following program; CincludeDstdio(hE int main+-9 char far 2p .+char far 2-0x////000/1 char far 2M .+char far 2-0x/777444/1 2p . A01 +2p-OO1 printf+QHdQ)2M-1 return 01 : )$* A0 )+* A, )C* A4 )D* Compilation error )E* one of a%ove

75

Output : (B)

E " p l a n a t i o n !
#ur%o COO 7(0* A, #ur%o C OO8(/* Compilation error [inux GCC* Compilation error =isual COO* Compilation error

"ar address of p physical address(

and

are

representing

same

Physical address of 0x////000/ . +0x////- 2 +0x,0O +0x000/- . 0x/////

Physical address of 0x/777444/ . +0x/777 2 0x,0- O +0x444/- . 0x///// 2p . A0) means content at memory location 0x///// is assigning value 4/ +2p-OO means increase the content %y one at memory location 0x//// so now content at memory location 0x///// is A, 2M also means content at memory location 0x///// which is 4>

85
!hat will %e output of following program; CincludeDstdio(hE CincludeDstring(hE int main+-9 char 2ptr, . U[[1 char 2ptr4 . 01 strcpy+ptr,)Q cQ-1 strcpy+ptr4)QMuestionsQ-1 printf+QRnHs HsQ)ptr,)ptr4-1 return 01 : )$* c Muestions )+* c +null)C* +null- +null)D* Compilation error )E* one of a%ove

Output : (C)

E " p l a n a t i o n !
#ur%o COO 7(0* +null- +null#ur%o C OO8(/* Kun time error [inux GCC* Kun time error

=isual COO* Kun time error

!e cannot assign any string constant in null pointer %y strcpy function(

95
!hat will %e output of following program; CincludeDstdio(hE int main+-9 int huge 2a .+int huge 2-0x/???000/1 int huge 2% .+int huge 2-0x/??A00,/1 if+a .. %printf+Qpower of pointerQ-1 else printf+Qpower of cQ-1 return 01 : )$* power of pointer )+* power of c )C* power of cpower of c )D* Compilation error )E* one of a%ove

Output : (A)

E " p l a n a t i o n !
#ur%o COO 7(0* power of pointer #ur%o C OO8(/* power of c [inux GCC* Compilation error =isual COO* Compilation error

Here we are performing relational operation %etween two huge addresses( So first of all %oth a and % will normaliNe as*

a. +0x/???-2 .0x???0O0x000/.0x???/ %. +0x/??A-2 .0x??A0O0x00,/.0x???/

+0x,0+0x,0-

O O

+0x000/+0x00,/same

Here %oth huge addresses are representing physical address( So a..% is true(

!hat will %e output of following program; CincludeDstdio(hE CincludeDstring(hE int main+-9 register a . 4/1 int far 2p1 p.3a1 printf+QHd Q)2p-1 return 01 : )$* 4/ )+* 8 )C* Address )D* Compilation error )E* one of a%ove

:5

Output : (D)

E " p l a n a t i o n !
#ur%o COO 7(0* Compilation error #ur%o C OO8(/* Compilation error [inux GCC* Compilation error =isual COO* Compilation error

Kegister data type stores in CPU( So it has not any memory address( Hence we cannot write 3a(

!hat will %e output of following program; CincludeDstdio(hE CincludeDstring(hE int main+-9 char far 2p)2M1 printf+QHd HdQ)siNeof+p-)siNeof+M--1 return 01 : )$* 4 4 )+* 8 8 )C* 8 4 )D* 4 8 )E* one of a%ove

;5

Output : (C)

E " p l a n a t i o n !
#ur%o COO 7(0* 8 8 #ur%o C OO8(/* 8 8 [inux GCC* Compilation error =isual COO* Compilation error

p is far pointer which siNe is 8 %yte( By default M is near pointer which siNe is 4 %yte(

<5

!hat will %e output of following program; CincludeDstdio(hE int main+-9 int a . ,01

void 2p . 3a1 int 2ptr . p1 printf+QHuQ)2ptr-1 return 01 :

)$* ,0 )+* Address )C* 3 )D* Compilation error )E* one of a%ove

Output : (A)

E " p l a n a t i o n !
#ur%o COO 7(0* ,0 #ur%o C OO8(/* ,0 [inux GCC* ,0 =isual COO* ,0

=oid pointer can hold address of any data type without type casting( Any pointer can hold void pointer without type casting(

-=5
!hat will %e output of following program; CincludeDstdio(hE CincludeDstring(hE int main+-9 int register a1 scanf+QHdQ)3a-1 printf+QHdQ)a-1 return 01 : FFif a.4/

)$* 4/ )+* Address )C* 0 )D* Compilation error )E* one of a%ove

Output : (D)

E " p l a n a t i o n !
#ur%o COO 7(0* Compilation error #ur%o C OO8(/* Compilation error [inux GCC* Compilation error =isual COO* Compilation error

Kegister data type stores in CPU( So it has not any memory address( Hence we cannot write 3a(

--5
!hat will %e output of following program; CincludeDstdio(hE int main+-9 char arr5,061 arr . QworldQ1 printf+QHsQ)arr-1 return 01 : )$* world )+* w )C* ull )D* Compilation error )E* one of a%ove

Output : (D)

E " p l a n a t i o n !

#ur%o COO 7(0* Compilation error #ur%o C OO8(/* Compilation error [inux GCC* Compilation error =isual COO* Compilation error

Compilation error [value reMuired Array name is constant pointer and we cannot assign any value in constant data type after declaration(

-35
!hat will %e output of following program; CincludeDstdio(hE CincludeDstring(hE int main+-9 int a)%)c)d1 char 2p . + char 2-01 int 2M . + int 2M-01 float 2r . + float 2-01 dou%le 2s . 01 a . +int-+pO,-1 % . +int-+MO,-1 c . +int-+rO,-1 d . +int-+sO,-1 printf+QHd Hd Hd HdQ)a)%)c)d-1 return 01 : )$* 4 4 4 4 )+* , 4 8 A )C* , 4 4 8 )D* Compilation error )E* one of a%ove

Output : (B)

E " p l a n a t i o n !

#ur%o COO 7(0* , 4 8 A #ur%o C OO8(/* Compilation error [inux GCC* Compilation error =isual COO* Compilation error Address O , . next address Since initial address of all data type is Nero( So its next address will %e siNe of data type(

-65
!hat will %e output of following program; CincludeDstdio(hE CincludeDstring(hE int main+-9 int a . /)% . ,0)c1 int 2p . 3a)2M . 3%1 c . p P M1 printf+QHdQ ) c-1 return 01 : )$* , )+* / )C* P/ )D* Compilation error )E* one of a%ove

Output : (A)

E " p l a n a t i o n !
#ur%o COO 7(0* , #ur%o C OO8(/* ,

[inux GCC* , =isual COO* 4

Difference of two same type of pointer is always one(

-75
!hat will %e output of following program; CincludeDstdio(hE unsigned long int +2 avg+--5769 static unsigned long int arr576 . 9,)4)7:1 return 3arr1 : int main+-9 unsigned long int +2ptr-5761 ptr . avg+-1 printf+QHdQ ) 2+2ptrO4--1 return 01 : )$* , )+* 4 )C* 7 )D* Compilation error )E* one of a%ove

Output : (C)

E " p l a n a t i o n !
#ur%o COO 7(0* 7 #ur%o C OO8(/* 7 [inux GCC* 7 =isual COO* 7

-85

!hat will %e output of following program; CincludeDstdio(hE int main+-9 int 2 p ) %1 % . siNeof+p-1 printf+QHdQ ) %-1 return 01 : )$* 4 )+* 8 )C* A )D* Compilation error )E* one of a%ove

Output : (E)

E " p l a n a t i o n !
#ur%o COO 7(0* 4 or 8 #ur%o C OO8(/* 4 or 8 [inux GCC* 8 =isual COO* 8 since in this Muestion it has not written p is which type of pointer( So its output will depend upon which memory model has selected( Default memory model is small(

-95

!hat will %e output of following program; CincludeDstdio(hE int main+-9 int i . / ) &1 int 2p ) 2M1 p . 3i1 M . 3&1 & . /1

printf+QHd HdQ)2p)2M-1 return 01 :

)$* / / )+* Address Address )C* / Address )D* Compilation error )E* one of a%ove

Output : (A)

E " p l a n a t i o n !
#ur%o COO 7(0* / / #ur%o C OO8(/* / / [inux GCC* / / =isual COO* / /

-:5

!hat will %e output of following program; CincludeDstdio(hE int main+-9 int i . /1 int 2p1 p . 3i1 printf+Q Hu HuQ) 23p ) 32p-1 return 01 : )$* / Address )+* Address Address )C* Address / )D* Compilation error )E* one of a%ove

Output : (B)

E " p l a n a t i o n !

#ur%o COO 7(0* Address Address #ur%o C OO8(/* Address Address [inux GCC* Address Address =isual COO* Address Address

Since 2 and 3 always cancel to each other( i(e( 23a . a so 23p . p which store address of integer i 32p . 32+3i- FFsince p . 3i . 3+23i. 3i So second output is also address of i

-;5
!hat will %e output of following program; CincludeDstdio(hE int main+-9 int i . ,001 printf+Qvalue of i * Hd addresss of i * HuQ)i)3i-1 iOO1 printf+QRnvalue of i * Hd addresss of i * HuQ)i)3i-1 return 01 :

)$* value of i * ,00 addresss of i * Address


value of i * ,0, addresss of i * Address

)+*

value of i * ,00 addresss of i * Address value of i * ,00 addresss of i * Address )C* value of i * ,0, addresss of i * Address value of i * ,0, addresss of i * Address )D* Compilation error )E* one of a%ove

Output : (A)

E " p l a n a t i o n !
#ur%o COO 7(0* value of i * ,00 addresss of i * Address value of i * ,0, addresss of i * Address #ur%o C OO8(/* value of i * ,00 addresss of i * Address value of i * ,0, addresss of i * Address [inux GCC* value of i * value of i * =isual COO* value of i * value of i * ,00 addresss of i * Address ,0, addresss of i * Address ,00 addresss of i * Address ,0, addresss of i * Address

!ithin the scope of any varia%le) value of varia%le may change %ut its address will never change in any modification of varia%le(

-<5
!hat will %e output of following program; CincludeDstdio(hE int main+-9 char far 2p .+char far 2-0x////000/1 char far 2M .+char far 2-0x/777444/1 2p . 4/1

+2p-OO1 printf+QHdQ)2M-1 return 01 :

)$* 4/ )+* Address )C* Gar%age )D* Compilation error )E* one of a%ove

Output : (E)

E " p l a n a t i o n !
#ur%o COO 7(0* 4> #ur%o C OO8(/* Compilation error [inux GCC* Compilation error =isual COO* Compilation error

"ar address of p and M are representing physical address( Physical address of 0x////000/ . 0x//// 2 ox,0 O ox000/ . 0x///// Physical address of 0x/777444/ . 0x/777 2 0x,0 O ox444/ . 0x/////

same

2p . 4/) means content at memory location 0x///// is assigning value 4/ +2p-OO means to increase the content %y one at memory the location 0x//// so now content of memory location at 0x///// is 4> 2M also means content at memory location 0x///// which is 4>

3=5
!hat will %e output of following program; CincludeDstdio(hE int main+-9 int i . 71 int 2&1 int 22'1 & . 3i1 ' . 3&1 printf+QHu Hu HuQ)i)&)'-1 return 01 : )$* 7 Address 7 )+* 7 Address Address )C* 7 7 7 )D* Compilation error )E* one of a%ove

Output : (B)

E " p l a n a t i o n !
#ur%o COO 7(0* 7 Address Address #ur%o C OO8(/* 7 Address Address [inux GCC* 7 Address Address =isual COO* 7 Address Address

Here >048) A0A/) ?0?, is any ar%itrary address) it may %e different(

C Command line argument Juestions with solution


Command line arguments in c example

+,-!hat will %e output of following c code; CincludeDstdio(hE int main+int count)char 2argv56-9 int i.01 for+i.01iDcount1iOOprintf+QRnHsQ)argv5i6-1 return 01 : FFsave file as arg(c $n command line C*RtcR%inEarg c techno tips Jutput* c techno tips +4- !hat will %e output of following c code; CincludeDdos(hE CincludeDstdio(hE int main+-9 printf+QHdQ)]argc-1 return 01 : FFsave file as countarg(c $n command line C*RtcR%inEcountarg a, a4 %, %4 +press enterJutput* / <xplanation* Here ]argc is glo%al identifier which has defined in dos(h(it count toal num%er of argument in command line(

+7-Keverse any string while string is passed throw command line; Answer* CincludeDstring(hE CincludeDstdio(hE int main+int count)char 2str56-9 printf+QHsQ)strrev+str5,6--1 return 01 :

+8- !hat will %e output following c code; CincludeDdos(hE CincludeDstdio(hE int main+-9 int i.01 for+i.01iD]argc1iOOprintf+QRnHsQ)]argv5i6-1 return 01 : FFsave file as arg(c $n command line C*RtcR%inEarg usa india &apan Jutput* Usa $ndia &apan

<xplanation* Here ]argc)]argv is glo%al identifier which has defined in dos(h(]arg count total num%er of argument in command line while ]argv is array of string which store all the argument in command line( +/- !rite a c program to create dos command type( Answer* Cinclude Dstdio(hE int main+int count)char 2 argv56-9 int i1 "$[< 2ptr1 char 2str1 char ch1 if+count..,-9 printf+Q#he syntax of the command is incorrect(RnQ-1 : for+i.,1iDcout1iOO-9 ptr.fopen+argv5i6)QrQ-1 if+ptr.. U[[-9 printf+Q#he system cannot find the file specified(Q-1 if+countE4printf+QRn<rror occurred while procesing * Hs(RnQ)argv5i6-1 : else9 if+countE4-9 printf+QHsRnRnQ)argv5i6-1

: Save the a%ove file as open(c) compile and execute the go to command mode +current wor'ing directoryand write* open xy(c +xy(c any file present in that directory#o run the open command in all directories and drive you will have to give the path of current wor'ing directory in command mode( !rite* C*tcR%inEPA#H c*RtcR%in ow press enter 'ey( ow your open command will wor' in all directory and drive( +>- !rite a c program to create dos command dir( Answer* CincludeDstdio(hE CincludeDdos(hE int main+int count)char 2argv56-9 struct find]t M 1 int a1 if+count..,argv5,6.Q2(2Q1 a . ]dos]findfirst+argv5,6),)3M-1 if+a..0-9 while +\a-9 printf+Q HsRnQ) M(name-1 a . ]dos]findnext+3M-1 : : else9 printf+Q"ile not foundQ-1 : return 01 :

: return 01

: fclose+ptr-1

: while++ch.getc+ptr--\.P,printf+QHcQ)ch-1

Save the a%ove file as list(c) compile and execute the go to command mode +current wor'ing directoryand write* list 2(c #o run the list command in all directories and drive you will have to give the path of current wor'ing directory in command mode( !rite* C*tcR%inEPA#H c*RtcR%in ow press enter 'ey( ow your list command will wor' in all directory and drive( $mage list +@-How can we display the entire environments vector %y c program; Answer* CincludeDstdio(hE int main+int count)char 2arg56)char 2argvect56-9 int i.01 while+argvect5i6- 9 printf+QRnHsQ)argvect5i6-1 iOO1 : return 01 : +A-!rite a c program which ta'es a string from command line with main function has no parameter and convert the string in uppercase; Answer* CincludeDdos(hE CincludeDstring(hE CincludeDstdio(hE int main+-9 char str5,/61 int i.01 strcpy+str)]argv5,6-1 for+i.01iD.strlen+str-1iOO-9 if+str5i6E.?@33str5i6D.,44str5i6.str5i6P741 : printf+QRnstring in uppercase * HsQ)str-1 return 01

C Juestions in L5NU9 c linux inter"iew Juestions C [inux interview Muestions and answers
+,-!hat will %e output if you will execute following program %y gcc compiler in [inux; CincludeDstdio(hE int main+-9 int a./1 printf+QHd Hd HdQ)aOO)aOO)OOa-1 return 01 : Jutput* $n [$ US GCC compiler @ > A $n #UKBJ C @ > > Hints* $n #ur%o c parameter is passed from right to left in printf function %ut not in the [inux( +4-!hat will %e output if you will execute following program %y gcc compiler in [inux; CincludeDstdio(hE int main+-9 int a./)%.,0)c.,/)d.401

printf+QHd Hd HdQ-1 return 01 : Jutput* $n [$ US GCC compiler Gar%age values $n #UKBJ C / ,0 ,/ Hints* [ocal varia%les stores in the stac'( +7- !hat will %e output if you will execute following program %y gcc compiler in [inux; CincludeDstdio(hE int main+-9 int i./)&./)y1 int x.OOi O OOi O OOi1 y.OO& O OO& O OO&1 printf+QHd Hd Hd HdQ)x)y)i)&-1 return 01 : Jutput* $n [$ US GCC compiler 44 44 A A $n #UKBJ C 4, 48 A A +8- !hat will %e output if you will execute following program %y gcc compiler in [inux; CincludeDstdio(hE int main+-9 int near 2p1 int far 2M1 int huge 2r1 printf+QHd Hd HdQ)siNeof+p-)siNeof+M-)siNeof+r--1 return 01 :

Jutput* $n [$ US GCC compiler Compilation error $n #UKBJ C 4 8 8 ote* $n [inux there is not any concept of near) far and huge pointers +/- !hat will %e output if you will execute following program %y gcc compiler in [inux; CincludeDstdio(hE int main+-9 char 2p1 int 2M1 float 22r1 printf+QHd Hd HdQ)siNeof+p-)siNeof+M-)siNeof+r--1 return 01 : Jutput* $n [$ US GCC compiler 8 8 8 $n #UKBJ C 4 4 4 Hints* siNe of any type of pointer in [inux is 8 and in tur%o c is 4( +>- !hat will %e output if you will execute following program %y gcc compiler in [inux; CincludeDstdio(hE int main+-9 short int a./1 int %./1 long int c./l1 float d./(0f1 dou%le e./(01 long dou%le f./(0[1

char g.W/W1 printf+QSiNe of printf+QSiNe of printf+QSiNe of printf+QSiNe of printf+QSiNe of printf+QSiNe of printf+QSiNe of return 01

short int* HdRnQ)siNeof+a--1 int* HdRnQ)siNeof+%--1 long int* HdRnQ)siNeof+c--1 float* HdRnQ)siNeof+d--1 dou%le* HdRnQ)siNeof+e--1 long dou%le* HdRnQ)siNeof+f--1 char* HdRnQ)siNeof+g--1

Jutput* $n [$ US GCC compiler SiNe of short int* 4 SiNe of int* 8 SiNe of long int* 8 SiNe of float* 8 SiNe of dou%le* A SiNe of long dou%le* ,4 SiNe of char* , $n #UKBJ C SiNe of short int* 4 SiNe of int* 4 SiNe of long int* 8 SiNe of float* 8 SiNe of dou%le* A SiNe of long dou%le* ,0 SiNe of char* , +@- !hat will %e output if you will execute following program %y gcc compiler in [inux; CincludeDstdio(hE int main+-9 int a.7001 char 2p.+char 2-3a1 printf+QHdRnQ)2p-1 printf+QHdQ)2OOp-1 return 01 :

Jutput* $n [$ US GCC compiler 88 , $n #UKBJ C 88 , +A- !hat will %e output if you will execute following program %y gcc compiler in [inux; CincludeDstdio(hE int main+-9 char c.WAW1 printf+QHd HdQ)siNeof+c-)siNeof+WAW--1 return 01 : Jutput* $n [$ US , 8 $n #UKBJ C , 4 +?- !hat will %e output if you will execute following program %y gcc compiler in [inux; CincludeDstdio(hE int main+-9 enum color9K<D)B[U<)GK<< .P4)L<[[J!)P$ Z:1 printf+QHd HdQ)B[U<)P$ Z-1 return 01 : Jutput* $n [$ US GCC compiler , 0 $n #UKBJ C , 0 +,0- !hat will %e output if you will execute following program %y gcc compiler in [inux;

CincludeDstdio(hE int main+-9 char c.,4@1 printf+QHdQ)OOc-1 printf+Q HdQ)OOc-1 return 01 : Jutput* $n [$ US GCC compiler P,4A P,4@ $n #UKBJ C P,4A P,4@ Hints* char data type cyclic property( +,,- !hat will %e output if you will execute following program %y gcc compiler in [inux; CincludeQstdio(hQ struct info,9 char 2title1 long int siNe1 dou%le grade1 :hero,1 union info49 char 2title1 long int siNe1 dou%le grade1 :hero41 int main+-9 printf+QSiNe of structure* HdRnQ)siNeof+hero,--1 printf+QSiNe of union* HdQ)siNeof+hero4--1 return 01 : Jutput* $n [$ US GCC compiler SiNe of structure* ,> SiNe of union* A $n #UKBJ C

SiNe of structure* ,8 SiNe of union* A +,4- !hat will %e output if you will execute following program %y gcc compiler in [inux; Cdefine siNe+x- +char 2-+xO,-P+char 2-x CincludeDstdio(hE int main+-9 long int 2p1 long dou%le 2M1 printf+QSiNe of long int* HdRnQ)siNe+p--1 printf+QSiNe of long dou%le* HdQ)siNe+M--1 return 01 : Jutput* $n [$ US GCC SiNe of long SiNe of long $n #UKBJ C SiNe of long SiNe of long

compiler int* 8 dou%le* ,4


int* 8 dou%le* ,0

+,7- !hat will %e output if you will execute following program %y gcc compiler in [inux; CincludeDstdio(hE int main+-9 int i.4)&./)'.71 int a.i33&E.'1 printf+QHdQ)a-1 return 01 : Jutput* $n [$ US GCC compiler , $n #UKBJ C ,

Hints* Any conditional or relational operator returns , if condition is true otherwise it returns 0(

C %ric#y Xuestion %ric#y c Juestions and answers


#ric'y c programs Muestion for interview and answers with explanation( #hese Muestions are for experienced persons(

C advanced interview Muestions and answers

+,- !hat will %e output if you will compile and execute the following c code; struct mar's9 int p*71 int c*71 int m*41 :1 void main+-9 struct mar's s.94)P>)/:1 printf+QHd Hd HdQ)s(p)s(c)s(m-1 : +a+%+c+d+e4 P> / 4 P> , 4 4 , Compiler error one of these

Answer* +c<xplanation* Binary value Binary value Binary value +Select last Binary value

of 4* 000000,0 +Select three two %itof >* 00000,,0 of P>* ,,,,,00,O,.,,,,,0,0 three %itof /* 00000,0, +Select last two %it-

Complete memory representation*

+4- !hat will %e output if you will compile and execute the following c code; void main+-9 int huge2p.+int huge2-0SC0/>777,1 int huge2M.+int huge2-0xC4//,78,1 2p.4001 printf+QHdQ)2M-1 : +a-0 +%-Gar%age value +c-null +d- 400 +e-Compiler error Answer* +d<xplanation* Physical address of huge pointer p Huge address* 0SC0/>777, Jffset address* 0x777, Segment address* 0SC0/> Physical address. Segment address 2 0S,0 O Jffset address .0SC0/> 2 0S,0 O0S777, .0SC0/>0 O 0S777, .0SC7A?, Physical address of huge pointer M Huge address* 0SC4//,78, Jffset address* 0x,78, Segment address* 0SC4// Physical address. Segment address 2 0S,0 O Jffset address .0SC4// 2 0S,0 O0S,78, .0SC4//0 O 0S,78,

.0SC7A?, Since %oth huge pointers p and M are pointing same physical address so content of M will also same as content of M( +7- !rite c program which display mouse pointer and position of pointer(+$n x coordinate) y coordinate-; Answer* CincludeIdos(hI CincludeIstdio(hI void main+9 union K<GS i)o1 int x)y)'1 FFshow mouse pointer i(x(ax.,1 intA>+0x77)3i)3o-1 while+\'%hit+-- FFits value will false when we hit 'ey in the 'ey %oard 9 i(x(ax.71 FFget mouse position x.o(x(cx1 y.o(x(dx1 clrscr+-1 printf+Q+Hd ) Hd-Q)x)y-1 delay+4/0-1 intA>+0x77)3i)3o-1 : getch+-1 : +8- !rite a c program to create dos command* dir( Answer* Step ,* !rite following code( Cinclude Gstdio(hI Cinclude Gdos(hI void main+int count)char 2argv56-9 struct find]t M 1 int a1

if+count..,argv5,6.Q2(2Q1 a . ]dos]findfirst+argv5,6),)3M-1 if+a..0-9 while +\a-9 printf+Q HsRnQ) M(name-1 a . ]dos]findnext+3M-1 : : else9 printf+Q"ile not foundQ-1 : : Step 4* Save the as list(c +Lou can give any nameStep 7* Compile and execute the file( Step 8* !rite clic' on My computer of !indow SP operating system and select properties( Step /* Select Advanced PE <nvironment =aria%les Step >* Lou will find following window* Clic' on new %utton +Button inside the red %ox-

Step @* !rite following* =aria%le name* path =aria%le value* c*RtcR%inRlist(c +Path where you have saved-

Step A* Jpen command prompt and write list and press enter( Command line argument tutorial( +>- !hat will %e output if you will compile and execute the following c code; void main+-9 int i.,01 static int x.i1 if+x..iprintf+Q<MualQ-1 else if+xEiprintf+QGreater thanQ-1 else printf+Q[ess thanQ-1

: +a+%+c+d+e<Mual Greater than [ess than Compiler error one of a%ove

Answer* +d<xplanation* static varia%les are load time entity while auto varia%les are run time entity( !e can not initialiNe any load time varia%le %y the run time varia%le( $n this example i is run time varia%le while x is load time varia%le( +@- !hat will %e output if you will compile and execute the following c code; void main+-9 int i1 float a./(41 char 2ptr1 ptr.+char 2-3a1 for+i.01iD.71iOOprintf+QHd Q)2ptrOO-1 : +a-0 0 0 0 +%-Gar%age Gar%age Gar%age Gar%age +c-,04 /> PA0 74 +d-,04 ,04 P?0 >8 +e-Compiler error Answer* +d<xplanation* $n c float data type is four %yte data type while char pointer ptr can point one %yte of memory at a time( Memory representation of float a./(4

ptr pointer will point first fourth %yte then third %yte then second %yte then first %yte( Content of fourth %yte* Binary value.0,,00,,0 Decimal value. >8O74O8O4.,04 Content of third %yte* Binary value.0,,00,,0 Decimal value.>8O74O8O4.,04 Content of second %yte* Binary value.,0,00,,0 Decimal value.P,4AO74O8O4.P?0 Content of first %yte* Binary value.0,000000 Decimal value.>8 ote* Character pointer treats MSB %it of each %yte i(e( left most %it of a%ove figure as sign %it( +A- !hat will %e output if you will compile and execute the following c code; void main+-9 int i1 dou%le a./(41 char 2ptr1 ptr.+char 2-3a1 for+i.01iD.@1iOOprintf+QHd Q)2ptrOO-1 : +a+%+c+d+eP/, P/4 P/4 P/4 P/4 P/4 40 >8 /, /4 /4 /4 /4 /4 40 >8 <ight gar%age values( Compiler error one of these

Answer* +a<xplanation* $n c dou%le data type is eight %yte data type while char pointer ptr can point one %yte of memory at a time( Memory representation of dou%le a./(4

ptr pointer will point first eighth %yte then seventh %yte then sixth %yte then fifth %yte then fourth %yte then third %yte then second %yte then first %yte as shown in a%ove figure( Content of eighth %yte* Binary value.,,00,,0, Decimal value. P,4AO>8OAO8O,.P/, Content of seventh %yte* Binary value.,,00,,00 Decimal value. P,4AO>8OAO8.P/4 Content of sixth %yte* Binary value.,,00,,00 Decimal value. P,4AO>8OAO8.P/4 Content of fifth %yte* Binary value.,,00,,00 Decimal value. P,4AO>8OAO8.P/4 Content of fourth %yte* Binary value.,,00,,00 Decimal value. P,4AO>8OAO8.P/4 Content of third %yte*

Binary value.,,00,,00 Decimal value. P,4AO>8OAO8.P/4 Content of second %yte* Binary value.0000,0,00 Decimal value.,>O8.40 Content of first %yte* Binary value.0,000000 Decimal value.>8 ote* Character pointer treats MSB %it of each %yte i(e( left most %it of a%ove figure as sign %it( +?- !hat will %e output if you will compile and execute the following c code; void main+-9 printf+QHsQ)QcQ QtechnoQ QtipsQ-1 : +a+%+c+d+ec techno tips c tips ctechnotips Compiler error

Answer* +d<xplanation* $n c string constant GxyI is same as GxI GyI +,0- !hat will %e output if you will compile and execute the following c code; void main+-9 printf+QHsQ)]]DA#<]]-1 : +a+%+c+d+eCurrent system date Current system date with time null Compiler error one of these

Answer* +a-

<xplanation* ]]DA#<]] is glo%al identifier which returns current system date( +,,- !hat will %e output if you will compile and execute the following c code; void main+-9 char 2str.QcPpointerQ1 printf+QH2(2sQ),0)@)str-1 : +a+%+c+d+ecPpointer cPpointer cPpoint cpointer null null cPpoint

Answer* +e<xplanation* Meaning of H2(2s in the printf function* "irst 2 indicates the width i(e( how many spaces will ta'e to print the string and second 2 indicates how many characters will print of any string( "ollowing figure illustrates output of a%ove code*

+,4- !hat will %e output if you will compile and execute the following c code; void start+-1 void end+-1 Cpragma startup start Cpragma exit end int static i1 void main+-9 printf+QRnmain function* HdQ)OOi-1 :

void start+-9 clrscr+-1 printf+QRnstart function* HdQ)OOi-1 : void end+-9 printf+QRnend function* HdQ)OOi-1 getch+-1 : +amain function* 4 start function* , end function*7 +%start function* , main function* 4 end function*7 +cmain function* 4 end function*7 start function* , +d- Compiler error +e- one of these Answer* +%<xplanation* <very c program start with main function and terminate with null statement( But Cpragma startup can call function &ust %efore main function and Cpragma exit +,7- !hat will %e output if you will compile and execute the following c code; void main+-9 int a.P,41 a.aEE71 printf+QHdQ)a-1 : +a+%+c+dP8 P7 P4 P?>

+e- Compiler error Answer *+ c<xplanation* Binary value of ,4 is* 00000000 0000,,00 Binary value of P,4 wills 4Ys complement of ,4 i(e(

So %inary value of P,4 is* ,,,,,,,, ,,,,0,00

Kight shifting rule* Kule ,* $f num%er is positive the fill vacant spaces in the left side %y 0( Kule 4* $f num%er is negative the fill vacant spaces in the left side %y ,( $n this case num%er is negative( So right shift all the %inary digits %y three space and fill vacant space %y , as shown following figure*

Since it is negative num%er so output will also a negative num%er %ut its 4Ys complement(

Hence final out put will %e*

And its decimal value is* 4 Hence output will %e*P4 +,8- !hat will %e output if you will compile and execute the following c code; Cinclude Qstring(hQ void main+-9 clrscr+-1 printf+QHdHdQ)siNeof+QstringQ-)strlen+QstringQ--1 getch+-1 : +a- > > +%- @ @ +c- > @ +d- @ > +e- one of these Answer* +d<xplanation* SiNeof operator returns the siNe of string including null character while strlen function returns length of a string excluding null character( +,/- !hat will %e output if you will compile and execute the following c code; void main+-9 static main1

int x1 x.call+main-1 clrscr+-1 printf+QHd Q)x-1 getch+-1 : int call+int address-9 addressOO1 return address1 : +a- 0 +%- , +c- Gar%age value +d- Compiler error +e- one of these Answer* +%<xplanation* As we 'now main is not 'eyword of c %ut is special type of function( !ord main can %e name varia%le in the main and other functions( +,>- !hat will %e output if you will compile and execute the following c code; void main+-9 int a)%1 a.,)7),/1 %.+4)8)>-1 clrscr+-1 printf+QHd Q)aO%-1 getch+-1 : +a- 7 +%- 4, +c- ,@ +d- @ +e- Compiler error Answer* +d<xplanation* $n c comma %ehaves as separator as well as operator( a.,) 7) ,/1

%. +4) 8) >-1 $n the a%ove two statements comma is wor'ing as operator( Comma en&oys least precedence and associative is left to right( Assigning the priority of each operator in the first statement*

Hence , will assign to a( Assigning the priority of each operator in the second statement*

+,@- !hat will %e output if you will compile and execute the following c code; int extern x1 void main+printf+QHdQ)x-1 x.41 getch+-1 : int x.471 +a+%+c+d+e0 4 47 Compiler error one of these

Answer* +c-

<xplanation* extern varia%les can search the declaration of varia%le any where in the program( +,A- !hat will %e output if you will compile and execute the following c code; void main+-9 int i.01 if+i..0-9 i.++/)+i.7--)i.,-1 printf+QHdQ)i-1 : else printf+QeMualQ-1 : +a+%+c+d+e/ 7 , eMual one of a%ove

Answer* +c<xplanation* +,?- !hat will %e output if you will compile and execute the following c code; void main+-9 int a.4/1 clrscr+-1 printf+QHo HxQ)a)a-1 getch+-1 : +a+%+c+d+e4/ 4/ 04/ 0x4/ ,4 84 7, ,? one of these

Answer* +d-

<xplanation* Ho is used to print the num%er in octal num%er format( Hx is used to print the num%er in hexadecimal num%er format( ote* $n c octal num%er starts with 0 and hexadecimal num%er starts with 0x( +40- !hat will %e output if you will compile and execute the following c code; Cdefine message Qunion isR power of cQ void main+-9 clrscr+-1 printf+QHsQ)message-1 getch+-1 : +a- union is power of c +%- union ispower of c +c- union is Power of c +d- Compiler error +e- one of these Answer* +%<xplanation* $f you want to write macro constant in new line the end with the character R( +4,- !hat will %e output if you will compile and execute the following c code; Cdefine call+x- Cx void main+-9 printf+QHsQ)call+cFcOO--1 : +a-c +%-cOO +c-CcFcOO +d-cFcOO

+e-Compiler error Answer* +d<xplanation* C is string operator( $t converts the macro function call argument in the string( "irst see the intermediate file* test(c ,* test(c 4* void main+-9 test(c 7* printf+QHsQ)QcFcOOQ-1 test(c 8* : test(c /* $t is clear macro call is replaced %y its argument in the string format( +44- !hat will %e output if you will compile and execute the following c code; void main+-9 if+printf+QctechnotipsQ-printf+Q$ 'now cQ-1 else printf+Q$ 'now cOOQ-1 : +a+%+c+d+e$ 'now c $ 'now cOO ctechnotips$ 'now c ctechnotips$ 'now cOO Compiler error

Answer* +c<xplanation* Keturn type of printf function is integer which returns num%er of character it prints including %lan' spaces( So printf function inside if condition will return ,7( $n if condition any nonP Nero num%er means true so else part will not execute( $f you have any dou%t in a%ove #ric'y Muestions with explanation you can as' through comment section(

Das könnte Ihnen auch gefallen