Decision-making, Branching, Looping & Bit-wise Operations

Embed Size (px)

DESCRIPTION

Decision-making, Branching, Looping & Bit-wise Operations

Citation preview

By : Nanda Kishor K N Mail ID : [email protected]_________________________________________________________________________________________________ C For Swimmers ______________ If u don't know how to swim, learn it now. Otherwise participate in the competition._________________________________________________________________________________________________ Topic : Decision-making, Branching, Looping & Bit-wise operations _____ _________________________________________________________************************************************************************************************** NOTE : All the programs are tested under Turbo C/C++ compilers. ** It is assumed that,** *=> Programs run under DOS environment,** *=> The underlying machine is an x86 system,** *=> Necessary header files are included.** *=> Program is compiled using Turbo C/C++ compiler.** The program output may depend on the information based on this assumptions. ** (For example sizeof(int) = 2 bytes may be assumed). **************************************************************************************************[Q001]. What will be the output of the following program :void main(){ printf("Hi!"); if (-1) printf("Bye");}(a)No Output (b)Hi! (c)Bye(d)Hi!ByeAns. (d)_________________________________________________________________________________________________[Q002]. What will be the output of the following program :void main(){ printf("Hi!"); if (0 || -1) printf("Bye");}(a)No Output (b)Hi! (c)Bye(d)Hi!ByeAns. (d) _________________________________________________________________________________________________[Q003]. What will be the output of the following program :void main(){ printf("Hi!"); if (!1) printf("Bye");}(a)Compile-Time error (b)Hi! (c)Bye(d)Hi!ByeAns. (b)_________________________________________________________________________________________________[Q004]. What will be the output of the following program :void main(){ printf("Hi!"); if !(0) printf("Bye");}(a)Compile-Time error (b)Hi! (c)Bye(d)Hi!ByeAns. (a)_________________________________________________________________________________________________[Q005]. What will be the output of the following program :void main(){ printf("Hi!"); if (-1+1+1+1-1-1-1+(-1)-(-1)) printf("Bye");}(a)No Output (b)Hi! (c)Bye(d)Hi!ByeAns. (d)_________________________________________________________________________________________________[Q006]. What will be the output of the following program :void main(){ if (sizeof(int) && sizeof(float) && sizeof(float)/2-sizeof(int))printf("Testing"); printf("OK");}(a)No Output (b)OK (c)Testing(d)TestingOKAns. (b)_________________________________________________________________________________________________[Q007]. What will be the output of the following program :void main(){ int a=1,b=2,c=3,d=4,e; if (e=(a & b | c ^ d)) printf("%d",e);}(a)0 (b)7 (c)3(d)No OutputAns. (b)_________________________________________________________________________________________________[Q008]. What will be the output of the following program :void main(){ unsigned val=0xffff; if (~val) printf("%d",val); printf("%d",~val);}(a)Compile-Time error (b)-1 (c)0(d)-1 0Ans. (c)_________________________________________________________________________________________________[Q009]. What will be the output of the following program :void main(){ unsigned a=0xe75f,b=0x0EF4,c; c=(a|b); if ((c > a) && (c > b)) printf("%x",c);}(a)No Output (b)0xe75f (c)0xefff(d)None of theseAns. (c)_________________________________________________________________________________________________[Q010]. What will be the output of the following program :void main(){ unsigned val=0xabcd; if (val>>16 | val b)printf("%d %d",d,c); else if (c > a)printf("%d %d",c,d); if (c > a)if (b < a) printf("%d %d",c,a);else if (b < c) printf("%d %d",b,c);}(a)4 3 3 4 (b)4 3 3 2 (c)4 32 3 (d)4 33 1Ans. (c)_________________________________________________________________________________________________[Q016]. What will be the output of the following program :void main(){ int a=1,b=2,c=3,d=4; if (d > c) if (c > b)printf("%d %d",d,c); if (c > a)printf("%d %d",c,d); if (c > a)if (b < a) printf("%d %d",c,a);if (b < c) printf("%d %d",b,c);}(a)4 32 3 (b)4 33 42 3 (c)4 3 3 4 2 3 (d)None of theseAns. (b)_________________________________________________________________________________________________[Q017]. What will be the output of the following program :void main(){ int a=1; if (a == 2); printf("C Program");}(a)No Output (b)C Program (c)Compile-Time ErrorAns. (b)_________________________________________________________________________________________________[Q018]. What will be the output of the following program :void main(){ int a=1; if (a) printf("Test"); else; printf("Again");}(a)Again (b)Test (c)Compile-Time Error(d)TestAgainAns. (d)_________________________________________________________________________________________________[Q019]. What will be the output of the following program :void main(){ int i=1; for (; i