Sei sulla pagina 1di 57

c quiz questions with answers

(1) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int a=5; float b; printf("%d",sizeof(++a+b)); printf(" %d",a); return 0; } (a)2 6 (b)4 6 (c)2 5 (d)4 5 (e)Compiler error Output: (d) Explanation: ++a +b =6 + Garbage floating point number =Garbage floating point number //From the rule of automatic type conversion Hence sizeof operator will return 4 because size of float data type in c is 4 byte.

Value of any variable doesnt modify inside sizeof operator. Hence value of variable a will remain 5. Properties of sizeof operator. Operators tutorial (2) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ char *str; scanf("%[^\n]",str); printf("%s",str); return 0; } (a)It will accept a word as a string from user. (b)It will accept a sentence as a string from user. (c)It will accept a paragraph as a string from user. (d)Compiler error (e)None of above Output: (b) Explanation: Task of % [^\t] is to take the stream of characters until it doesnt receive new

line character \t i.e. enter button of your keyboard. General meaning of %[^ p] String tutorial. (3) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int array[3]={5}; int i; for(i=0;i<=2;i++) printf("%d ",array[i]); return 0; } (a)5 garbage garbage (b)5 0 0 (c)5 null null (d)Compiler error (e)None of above Output: (b) Explanation: Storage class of an array which initializes the element of the array at the time of declaration is static. Default initial value of static integer is zero. Properties of static storage class. How to read complex array.

(4) What will be output if you will compile and execute the following c code? #include<stdio.h> void call(int,int,int); int main(){ int a=10; call(a,a++,++a); return 0; } void call(int x,int y,int z){ printf("%d %d %d",x,y,z); } (a)10 10 12 (b)12 11 11 (c)12 12 12 (d)10 11 12 (e)Compiler error Output: (b) Explanation: Default parameter passing scheme of c is cdecl i.e. argument of function will pass from right to left direction.

First ++a will pass and a=11 Then a++ will pass and a=11 Then a will pass and a=12 What is pascal and cedecl parameter passing scheme? Concept of variable numbers of argument. (5) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int x=5,y=10,z=15; printf("%d %d %d"); return 0; } (a)Garbage Garbage Garbage (b)5 10 15 (c)15 10 5 (d)Compiler error (e)Run time error Output: (c) Explanation:

Auto variables are stored in stack as shown in following figure.

Stack follow LIFO data structure i.e. last come and first out. First %d will print then content of two continuous bytes from the top of the stack and so on. Memory map tutorial. More questions based on memory map. (6) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){

register int i,x; scanf("%d",&i); x=++i + ++i + ++i; printf("%d",x); return 0; } (a)17 (b)18 (c)21 (d)22 (e)Compiler error Output: (e) Explanation: In c register variable stores in CPU it doesnt store in RAM. So register variable have not any memory address. So it is illegal to write &a. Complete tutorial of storage class with examples. Properties of register storage class. (7) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int a=5; int b=10;

{ int a=2; a++; b++; } printf("%d %d",a,b); return 0; } (a)5 10 (b)6 11 (c)5 11 (d)6 10 (e)Compiler error Output: (c) Explanation: Default storage class of local variable is auto. Scope and visibility of auto variable is within the block in which it has declared. In c, if there are two variables of the same name then we can access only local variable. Hence inside the inner block variable a is local variable which has declared and defined inside that block. When control comes out of the inner block local variable a became dead. Complete tutorial of storage class with examples. What is auto storage class?

(8) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ float f=3.4e39; printf("%f",f); return 0; } (a)3.4e39 (b)3.40000 (c)+INF (d)Compiler error (e)Run time error Output: (c) Explanation: If you will assign value beyond the range of float data type to the float variable it will not show any compiler error. It will store infinity. Data type tutorial with examples. Concept of float data type. (9) What will be output if you will compile and execute the following c code? #include<stdio.h>

int main(){ enum color{ RED,GREEN=-20,BLUE,YELLOW }; enum color x; x=YELLOW; printf("%d",x); return 0; } (a)-22 (b)-18 (c)1 (d)Compiler error (e)None of above Output: (b) Explanation: Default value of enum constant = value of previous enum constant +1 Default value of first enum constant=0 Hence: BLUE=GREEN+1=-20+1=-19 YELLOW=BLUE+1=-19+1=-18 Complete tutorial of enum data type with examples. (10) What will be output if you will compile and execute the following c code?

#include<stdio.h> int main(){ asm{ mov bx,8; mov cx,10 add bx,cx; } printf("%d",_BX); return 0; } (a)18 (b)8 (c)0 (d)Compiler error (e)None of above Output: (a) Explanation: asm keyword is used to write assembly language program in c. mov command stores the constants in the register bx, cx etc. add command stores the content of register and stores in first register i.e. in bx. How to write assembly language program by c? Advance c tutorial. (11) What will be output if you will compile and execute the following c code?

#include<stdio.h> int main(){ enum xxx{ a,b,c=32767,d,e }; printf("%d",b); return 0; } (a)0 (b)1 (c)32766 (d)Compiler error (e)None of above Output: (d) Explanation: Size of enum constant is size of sign int. Since value of c=32767. Hence value of d will be 32767+1=32768 which is beyond the range of enum constant. Tutorial of data type with examples. (12) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ signed int a=-1;

unsigned int b=-1; if(a==b) printf("%d %d",a,b); else printf("Not equal"); return 0; } (a)-1 -1 (b)-1 32767 (c)-1 -32768 (d)Not equal (e)Compiler error

Output: (a) Explanation: What is automatic type conversion? (13) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ float f=5.5f; float x; x=f%2;

printf("%f",x); return 0; } (a)1.500000 (b)1.000000 (c)5.500000 (d)Compiler error (e)None of above Output: (d) Explanation: Modular division is not allowed floating number. Properties of modular division. Operators tutorial with examples.

with

(14) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int a=-20; int b=-3; printf("%d",a%b); return 0; } (a)2 (b)-2 (c)18

(d)-18 (e)Compiler error Output: (b) Explanation: Sign of resultant of modular division depends upon only the sign of first operand. Properties of modular division. Operators tutorial with examples. (15) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ char c='0'; printf("%d %d",sizeof(c),sizeof('0')); return 0; } (a)1 1 (b)2 2 (c)1 2 (d)2 1 (e)None of above Output: (c) Size of char data type is one byte while size of character constant is two byte.

Why character constant is of two byte in c? (16) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ char *url="c:\tc\bin\rw.c"; printf("%s",url); return 0; } (a)c:\tc\bin\rw.c (b)c:/tc/bin/rw.c (c)c: c inw.c (d)c:cinw.c (e)w.c in Output: (e) Explanation: 1. \t is tab character which moves the cursor 8 space right. 2. \b is back space character which moves the cursor one space back. 3. \r is carriage return character which moves the cursor beginning of the line.

Complete string tutorial with examples. Properties of escape characters. (17) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ goto abc; printf("main"); return 0; } void dispaly(){ abc: printf("display"); } (a)main (b)display

(c)maindisplay (d)displaymain (e)Compiler error Output: (e) Explanation: Label of goto cannot be in other function because control cannot move from one function to another function directly otherwise it will show compiler error: unreachable label What is goto keyword. Complete function tutorial with examples. (18) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int i=3; if(3==i) printf("%d",i<<2<<1); else printf("Not equal"); } (a)1 (b)48 (c)24 (d)Not equal

(e)Compiler error Output: (c) Explanation: Associative of bitwise left shifting operator is left to right. In the following expression: i<<2<<1 There are two bitwise operators. From rule of associative leftmost operator will execute first. i <<><<> After execution of leftmost bitwise left shifting operator: so i=i*pow(2,2) =3* What is associative? What is precedence? Tutorial of bitwise operators. (19) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int x=2,y=3; if(x+y<=5) printf("True"); else printf("False");

} (a)True (b)False (c)Compiler error: Lvalued required (d)Compiler error: Invalid expression (e)None of above Output: (a) Explanation: Expression x+y<=5 => 2+3 <=5 => 5<=5 is true because 5 is either greater than 5 or equal to 5. Operator tutorial with examples. (20) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ const int i=5; i++; printf("%d",i); return 0; } (a)5 (b)6 (c)0 (d)Compiler error

(e)None of above Output: (d) Explanation: We cannot modify the const variable using increment operator. Properties of const keyword. Properties of volatile keyword. Data type tutorial with examples.

by

(21) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int i=11; int const * p=&i; p++; printf("%d",*p); return 0; } (a)11 (b) 12 (c)Garbage value (d)Compiler error (e)None of above Output: (c) Explanation: In the following line:

int const * p=&i; *p i.e. content of p is constant pointer p is not constant pointer. So we can modify the pointer p. After incrementing the pointer it will point next memory location and its content will any garbage value.

Note: We address.

have

assumed

arbitrary

memory pointer

To make pointer p as constant write: int const * const p=&i; Properties of const keyword. Properties of volatile keyword.

(22) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int a=15,b=10,c=5; if(a>b>c ) printf("Trre"); else

printf("False"); return 0; } (a)True (b)False (c)Run time error (d)Compiler error (e)None of above Output: (b) Explanation: Relation operator in c always returns 1 when condition is true and 0 when condition is false. So in the following expression a > b > c Associative of relational operators are left to right order of execution will be following manner:

Hence in this expression first solve bolded condition: a > b > c Since condition a>b is true so result will be 1. Now expression became: 1 > c Since this condition is false so result will be 0. Thus else part will execute.

What is associative? What is precedence? (23) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ float f; f=3/2; printf("%f",f); return 0; } (a)1.5 (b)1.500000 (c)1.000000 (d)Compiler error (e)None of above Output: (c) Explanation: In the following expression: f=3/2 both 3 and 2 are integer constant hence its result will also be an integer constant i.e. 1. Properties of floating type numbers. (24) What will be output if you will compile and execute the following c code?

#include<stdio.h> int main(){ int a=sizeof(a); a=modify(a); printf("%d",a); return 0; } int modify(int x){ int y=3; _AX=x+y; return; } (a)2 (b)3 (c)5 (d)Garbage value (e)None of above Output: (c) Explanation: _AX is register pseudo variable. It stores return type of function. What is register pseudo variable? What is global identifier? (25) What will be output if you will compile and execute the following c code? #define PRINT printf("c");printf("c++"); int main(){ float a=5.5;

if(a==5.5) PRINT else printf("Not return 0; } (a)c c++ (b)Not equal (c)c c++ (d)Compiler error (e)None of above Output: (d) Explanation: First see intermediate file: try.c 1: try.c 2: int main(){ try.c 3: float a=5.5; try.c 4: if(a==5.5) try.c 5: printf("c");printf("c++"); try.c 6: else try.c 7: printf("Not equal"); try.c 8: } try.c 9: return 0; try.c 10: If there are more than one statement in if block then it is necessary to write inside the { } otherwise it will show compiler error: misplaced else equal");

More questions on preprocessors. Preprocessor tutorial with

examples.

(26) What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int array[2][2][3]={0,1,2,3,4,5,6,7,8,9,1 0,11}; printf("%d",array[1][0][2]); return 0; } (a)4 (b)5 (c)6 (d)7 (e)8 Output: 8 Explanation: array[1][0][2] 1*(2*3)+0*(3)+3=9th element of starting from zero i.e. 8. Questions on two dimension array. Complete tutorial of array.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

means array

What is the name of the man who is invented to c? 1. chals babes 2. Dennis ritchie 3. Dennis brown 4. None Questions What is the name of the man who is invented to c? 1. chals babes 2. Dennis ritchie 3. Dennis brown 4. None Answers Post Posted Answers By

Dennis ritchie

What is the stand form is FORTRAN? 1. Format translater 2. Form transmission 3. Formula translator 4. none Questions What is the stand form is FORTRAN? 1. Format translater Formula translator 2. Form transmission 3. Formula translator 4. none Answers Post Posted Answers By

What is the stand form of COBOL? 1. Common business oriented language 2. Combination of language 3. Common Body language 4. none Common business oriented language

++++++++++++++++++++++++++
What is the stand form of the 1. Basic combined programming 2. Basic programming combined 3. Basic compiler programming 4. none BPCL? language language language

Basic combined programming language

+++++++++++++++++++++++++++++++
Why we use the comma operator? 1. for termination 2. for separation 3. All 4. none for separation

+++++++++++++++++++++++++++
What is the mean of type casting? 1. Conversion of the Data item 2. Conversion of variables 3. fixed the value of Data item 4. none Conversion of the Data item

+++++++++++++++++++++++
What will be the output?main(){int a=10;int b=5;int c=5;int d=2;int e=a*d +b/c;printf("e=%d",e);} 1. error 2. 4 3. 20 4. none 21

What will be the output?main(){int a=5;b=10;temp;temp=a;a=b;b=temp;printf(\"a=%d\\t\\tb=%d\",a,b);} 1. a=5, b=10 2. error 3. a=10, b=5 4. none a=10, b=5

What will be the output?main(){int a=10;b=5;int c=a%b;printf(\"%d\",c);} 1. error 2. 0 3. 2 4. none 0

What will be the output? main(){ int n=125,sum=0,re; while(n>0){ re=n%10; sum+=re; n/=10;} printf("sum is=%d",sum);} 1. error

2. 8 3. 6 4. none 8

V
What will be the output? main(){ int i; for(i=1;i<=10;i++){ printf("Number is=%d",i);} 1. error 2. 1,2,3,4,5,6,7,8,9,10 3. 1,2,3,4,5,6,7,8,9 4.none 1,2,3,4,5,6,7,8,9,10 What will be the output? main(){ int i; for(i=1;i<=10;i++){ printf("Number is=%d",i);} 1. error 2. 1,2,3,4,5,6,7,8,9,10 3. 1,2,3,4,5,6,7,8,9 4.none 1,2,3,4,5,6,7,8,9,10

What will be the output of this program? main(){ int i=10; printf("value=%d",i++); printf("value=%d",i); } 1. i=10,i=11 2. error 3. compilation failed 4. none i=10,i=11

What will be the output of the program? int main() { printf("World"); main(); return 0; } A. B. C. D. D Infinite times 32767 times 65535 times Till stack doesn't overflow

What will be the output of the program? int main() { printf("World"); main(); return 0; } A. B. C. D. D Infinite times 32767 times 65535 times Till stack doesn't overflow

Tricky c questions and answers

Tricky c programs question for interview and answers explanation. These questions are for experienced persons.

with

C advanced interview questions and answers (1) What will be output if you will compile and execute the following c code? struct marks{ int p:3; int c:3; int m:2; }; void main(){ struct marks s={2,-6,5}; printf("%d %d %d",s.p,s.c,s.m); } (a) 2 -6 5

(b) (c) (d) (e)

2 -6 1 2 2 1 Compiler error None of these

Answer: (c) Explanation: Binary value of 2: 00000010 (Select three two bit) Binary value of 6: 00000110 Binary value of -6: 11111001+1=11111010 (Select last three bit) Binary value of 5: 00000101 (Select last two bit) Complete memory representation:

(2) What will be output if you will compile and execute the following c code? void main(){ int huge*p=(int huge*)0XC0563331; int huge*q=(int huge*)0xC2551341; *p=200; printf("%d",*q); } (a)0

(b)Garbage value (c)null (d) 200 (e)Compiler error Answer: (d) Explanation: Physical address of huge pointer p Huge address: 0XC0563331 Offset address: 0x3331 Segment address: 0XC056 Physical address= Segment address * 0X10 + Offset address =0XC056 * 0X10 +0X3331 =0XC0560 + 0X3331 =0XC3891 Physical address of huge pointer q Huge address: 0XC2551341 Offset address: 0x1341 Segment address: 0XC255 Physical address= Segment address * 0X10 + Offset address =0XC255 * 0X10 +0X1341 =0XC2550 + 0X1341 =0XC3891 Since both huge pointers p and q are pointing same physical address so content of q will also same as content of q. (3) Write c program which display mouse pointer and position of pointer.(In x coordinate, y coordinate)?

Answer: #includedos.h #includestdio.h void main() { union REGS i,o; int x,y,k; //show mouse pointer i.x.ax=1; int86(0x33,&i,&o); while(!kbhit()) //its value will false when we hit key in the key board { i.x.ax=3; //get mouse position x=o.x.cx; y=o.x.dx; clrscr(); printf("(%d , %d)",x,y); delay(250); int86(0x33,&i,&o); } getch(); } (4) Write a command: dir. Answer: Step 1: Write following code. #include stdio.h #include dos.h c program to create dos

void main(int count,char *argv[]){ struct find_t q ; int a; if(count==1) argv[1]="*.*"; a = _dos_findfirst(argv[1],1,&q); if(a==0){ while (!a){ printf(" %s\n", q.name); a = _dos_findnext(&q); } } else{ printf("File not found"); } } Step 2: Save the as list.c (You can give any name) Step 3: Compile and execute the file. Step 4: Write click on My computer of Window XP operating system and select properties. Step 5: Select Advanced -> Environment Variables Step 6: You will find following window: Click on new button (Button inside the red box)

Step 7: Write following: Variable name: path Variable value: c:\tc\bin\list.c where you have saved)

(Path

Step 8: Open command prompt and write list and press enter. Command line argument tutorial. (6) What will be output if you will compile and execute the following c code? void main(){ int i=10; static int x=i; if(x==i) printf("Equal"); else if(x>i) printf("Greater than"); else printf("Less than"); }

(a) (b) (c) (d) (e)

Equal Greater than Less than Compiler error None of above

Answer: (d) Explanation: static variables are load time entity while auto variables are run time entity. We can not initialize any load time variable by the run time variable. In this example i is run time variable while x is load time variable. Properties of static variables. Properties of auto variables. (7) What will be output if you will compile and execute the following c code? void main(){ int i; float a=5.2; char *ptr; ptr=(char *)&a; for(i=0;i<=3;i++) printf("%d ",*ptr++); } (a)0 0 0 0 (b)Garbage Garbage Garbage Garbage (c)102 56 -80 32

(d)102 102 -90 64 (e)Compiler error Answer: (d) Explanation: In c float data type is four byte data type while char pointer ptr can point one byte of memory at a time. Memory representation of float a=5.2

ptr pointer will point first fourth byte then third byte then second byte then first byte. Content of fourth byte: Binary value=01100110 Decimal value= 64+32+4+2=102 Content of third byte: Binary value=01100110 Decimal value=64+32+4+2=102 Content of second byte: Binary value=10100110 Decimal value=-128+32+4+2=-90 Content of first byte:

Binary value=01000000 Decimal value=64 Note: Character pointer treats MSB bit of each byte i.e. left most bit of above figure as sign bit. (8) What will be output if you will compile and execute the following c code? void main(){ int i; double a=5.2; char *ptr; ptr=(char *)&a; for(i=0;i<=7;i++) printf("%d ",*ptr++); } (a) (b) (c) (d) (e) -51 -52 -52 -52 -52 -52 20 64 51 52 52 52 52 52 20 64 Eight garbage values. Compiler error None of these

Answer: (a) Explanation: In c double data type is eight byte data type while char pointer ptr can point one byte of memory at a time. Memory representation of double a=5.2

ptr pointer will point first eighth byte then seventh byte then sixth byte then fifth byte then fourth byte then third byte then second byte then first byte as shown in above figure. Content of eighth byte: Binary value=11001101 Decimal value= -128+64+8+4+1=-51 Content of seventh byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of sixth byte: Binary value=11001100 Decimal value= -128+64+8+4=-52

Content of fifth byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of fourth byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of third byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of second byte: Binary value=000010100 Decimal value=16+4=20 Content of first byte: Binary value=01000000 Decimal value=64 Note: Character pointer treats MSB bit of each byte i.e. left most bit of above figure as sign bit. (9) What will be output if you will compile and execute the following c code? void main(){ printf("%s","c" "question" "bank"); } (a) (b) (c) (d) (e) c question bank c bank cquestionbank Compiler error

Answer: (d)

Explanation: In c string constant xy is same as x y String tutorial. (10) What will be output if you will compile and execute the following c code? void main(){ printf("%s",__DATE__); } (a) (b) (c) (d) (e) Current system date Current system date with time null Compiler error None of these

Answer: (a) Explanation: __DATE__ is global identifier which returns current system date. (11) What will be output if you will compile and execute the following c code? void main(){ char *str="c-pointer"; printf("%*.*s",10,7,str); } (a) c-pointer (b) c-pointer

(c) c-point (d) cpointer null null (e) c-point Answer: (e) Explanation: Meaning of %*.*s in the printf function: First * indicates the width i.e. how many spaces will take to print the string and second * indicates how many characters will print of any string. Following figure illustrates output of above code:

Properties of printf function. (12) What will be output if you will compile and execute the following c code? void start(); void end(); #pragma startup start #pragma exit end int static i; void main(){ printf("\nmain function: %d",++i); }

void start(){ clrscr(); printf("\nstart function: %d",++i); } void end(){ printf("\nend function: %d",++i); getch(); } (a) main function: 2 start function: 1 end function:3 (b) start function: 1 main function: 2 end function:3 (c) main function: 2 end function:3 start function: 1 (d) Compiler error (e) None of these Answer: (b) Explanation: Every c program start with main function and terminate with null statement. But #pragma startup can call function just before main function and #pragma exit What is pragma directive? Preprocessor tutorial.

(13) What will be output if you will compile and execute the following c code? void main(){ int a=-12; a=a>>3; printf("%d",a); } (a) (b) (c) (d) (e) -4 -3 -2 -96 Compiler error

Answer :( c) Explanation: Binary value of 12 is: 00000000 00001100 Binary value of -12 wills 2s complement of 12 i.e.

So binary 11110100

value

of

-12

is:

11111111

Right shifting rule: Rule 1: If number is positive the fill vacant spaces in the left side by 0. Rule 2: If number is negative the fill vacant spaces in the left side by 1. In this case number is negative. So right shift all the binary digits by three space and fill vacant space by 1 as shown following figure:

Since it is negative number so output will also a negative number but its 2s complement.

Hence final out put will be:

And its decimal value is: 2 Hence output will be:-2 (14) What will be output if you will compile and execute the following c code? #include "string.h" void main(){ clrscr(); printf("%d%d",sizeof("string"),strlen("str ing")); getch(); } (a) 6 6 (b) 7 7 (c) 6 7 (d) 7 6 (e) None of these Answer: (d) Explanation: Sizeof operator returns the size of string including null character while strlen function returns length of a string excluding null character. (15) What will be output if you will compile and execute the following c code? void main(){ static main;

int x; x=call(main); clrscr(); printf("%d ",x); getch(); } int call(int address){ address++; return address; } (a) 0 (b) 1 (c) Garbage value (d) Compiler error (e) None of these Answer: (b) Explanation: As we know main is not keyword of c but is special type of function. Word main can be name variable in the main and other functions. What is main function in c? (16) What will be output if you will compile and execute the following c code? void main(){ int a,b; a=1,3,15; b=(2,4,6); clrscr(); printf("%d ",a+b);

getch(); } (a) (b) (c) (d) (e) 3 21 17 7 Compiler error

Answer: (d) Explanation: In c comma behaves as separator as well as operator. a=1, 3, 15; b= (2, 4, 6); In the above two statements comma is working as operator. Comma enjoys least precedence and associative is left to right. Assigning the priority of each operator in the first statement:

Hence 1 will assign to a. Assigning the priority of each operator in the second statement:

(17) What will be output if you will compile and execute the following c code? int extern x; void main() printf("%d",x); x=2; getch(); } int x=23; (a) (b) (c) (d) (e) 0 2 23 Compiler error None of these

Answer: (c) Explanation: extern variables can search the declaration of variable any where in the program. (18) What will be output if you will compile and execute the following c code? void main(){ int i=0; if(i==0){

i=((5,(i=3)),i=1); printf("%d",i); } else printf("equal"); } (a) (b) (c) (d) (e) 5 3 1 equal None of above

Answer: (c) Explanation: (19) What will be output if you will compile and execute the following c code? void main(){ int a=25; clrscr(); printf("%o %x",a,a); getch(); } (a) (b) (c) (d) (e) 25 25 025 0x25 12 42 31 19 None of these

Answer: (d) Explanation:

%o is used to print the number in octal number format. %x is used to print the number in hexadecimal number format. Note: In c octal number starts with 0 and hexadecimal number starts with 0x. (20) What will be output if you will compile and execute the following c code? #define message "union is\ power of c" void main(){ clrscr(); printf("%s",message); getch(); } (a) union is power of c (b) union ispower of c (c) union is Power of c (d) Compiler error (e) None of these Answer: (b) Explanation: If you want to write macro constant in new line the end with the character \. (21) What will be output if you will compile and execute the following c code? #define call(x) #x

void main(){ printf("%s",call(c/c++)); } (a)c (b)c++ (c)#c/c++ (d)c/c++ (e)Compiler error Answer: (d) Explanation: # is string operator. It converts the macro function call argument in the string. First see the intermediate file: test.c 1: test.c 2: void main(){ test.c 3: printf("%s","c/c++"); test.c 4: } test.c 5: It is clear macro call is replaced by its argument in the string format. (22) What will be output if you will compile and execute the following c code? void main(){ if(printf("cquestionbank")) printf("I know c"); else printf("I know c++"); }

(a) (b) (c) (d) (e)

I know c I know c++ cquestionbankI know c cquestionbankI know c++ Compiler error

Answer: (c) Explanation: Return type of printf function is integer which returns number of character it prints including blank spaces. So printf function inside if condition will return 13. In if condition any non- zero number means true so else part will not execute. If you have any doubt in above Tricky questions with explanation you can ask through comment section.

JAVA
of the source code? a) True b) False true

1) The Java interpreter is used for the execution

2) On successful compilation a file with the class extension is created? a) True b) False true

3) The Java source code can be created in a Notepad editor? a) True b) False true

4) The Java Program is enclosed in a class definition. a) True b) False true

5) Java supports multidimensional arrays? a)False b)True true

6)An array of arrays can be created. a)True b)False true 8)When a string literal is used in the program, Java automatically creates instances of the string class? a)True b)False true

9)Which 1. 2. 3. 4. byte

of the following are primitive types? byte String integer Float

10)What is the 1. 0 to 2 2. 0 to 2 3. 0 to 2 4. 0 to 2 0 to 2 15-1

range of the char type? 16 15 16-1 15-1

12) Strings are instances of the class String?

a)True b)False true

11)Converting of primitive types to objects can be explicitly. a)True b)False false

JAVA

Potrebbero piacerti anche