Search This Blog

Wednesday, 5 December 2012

c and c++ questions

These are the questions that appeared in the written test of various MNC's which include Google and Intergraph.

1.  What will be output if you will compile and execute the following c code?
void main(){
int a=5;
float b;
printf("%d",sizeof(++a+b));
printf(" %d",a);
}

(a)2 6
(b)4 6
(c)2 5
(d)4 5
(e)Compiler error

2.  What will be output if you will compile and execute the following c    
code?
void main(){
char *str;
scanf("%[^\n]",str);
printf("%s",str);
}
(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

3.  What will be output if you will compile and execute the following c code?
void main(){
int array[3]={5};
int i;
for(i=0;i<=2;i++)
printf("%d ",array[i]);
}

(a)5 garbage garbage
(b)5 0 0
(c)5 null null
(d)Compiler error
(e)None of above

4.  What will be output if you will compile and execute the following c code?
void main(){
int array[2][2][3]={0,1,2,3,4,5,6,7,8,9,10,11};
printf("%d",array[1][0][2]);
}

(a)4
(b)5
(c)6
(d)7
(e)8




5.  What will be output if you will compile and execute the following c code?
void call(int,int,int);
void main(){
int a=10;
call(a,a++,++a);
}
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
6.  What will be output if you will compile and execute the following c code?
void main(){
int x=5,y=10,z=15;
printf("%d %d %d");
}

(a)Garbage Garbage Garbage
(b)5 10 15
(c)15 10 5
(d)Compiler error
(e)Run time error
7.  What will be output if you will compile and execute the following c code?
void main(){
register int i,x;
scanf("%d",&i);
x=++i + ++i + ++i;
printf("%d",x);
}

(a)17
(b)18
(c)21
(d)22
(e)Compiler error
8.  What will be output if you will compile and execute the following c code?
void main(){
int a=5;
int b=10;
{
int a=2;
a++;
b++;
}
printf("%d %d",a,b);
}

(a)5 10
(b)6 11
(c)5 11
(d)6 10
(e)Compiler error

9.  What will be output if you will compile and execute the following c code?
void main(){
float f=3.4e39;
printf("%f",f);
}

(a)3.4e39
(b)3.40000…
(c)+INF
(d)Compiler error
(e)Run time error
10. What will be output if you will compile and execute the following c                      code?
void main(){
enum color{
RED,GREEN=-20,BLUE,YELLOW
};
enum color x;
x=YELLOW;
printf("%d",x);
}

(a)-22
(b)-18
(c)1
(d)Compiler error
(e)None of above
11. What will be output if you will compile and execute the following c                              code?
void main(){
asm{
mov bx,8;
mov cx,10
add bx,cx;
}
printf("%d",_BX);
}
(a)18
(b)8
(c)0
(d)Compiler error
(e)None of above
12. What will be output if you will compile and execute the following c code?
void main(){
enum xxx{
a,b,c=32767,d,e
};
printf("%d",d);
}
(a)0
(b)1
(c)32766
(d)Compiler error
(e)None of above
13. What will be output if you will compile and execute the following c code?
void main(){
signed int a=-1;
unsigned int b=-1;
if(a==b)
printf("%d %d",a,b);
else
printf("Not equal");
}

(a)-1 -1
(b)-1 32767
(c)-1 -32768
(d)Not equal
(e)Compiler error

14. What will be output if you will compile and execute the following c code?
void main(){
float f=5.5f;
float x;
x=f%2;
printf("%f",x);
}
                   
(a)1.500000
(b)1.000000
(c)5.500000
(d)Compiler error
(e)None of above 

15.  What will be output if you will compile and execute the following c                                                    
           code?
void main(){
int a=-20;
int b=-3;
printf("%d",a%b);
}

(a)2
(b)-2
(c)18
(d)-18
(e)Compiler error
16. What will be output if you will compile and execute the following c
code?
void main(){
char c='0';
printf("%d %d",sizeof(c),sizeof('0'));
}
         
(a)1 1
(b)2 2
(c)1 2
(d)2 1
(e)None of above
17.  What will be output if you will compile and execute the following c
        code?
void main(){
char *url="c:\tc\bin\rw.c";
printf("%s",url);
}       
(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
18. What will be output if you will compile and execute the following c
       code?
void main(){
clrscr();
goto abc;
printf("main");
getch();
}
void dispaly(){
abc:
printf("display");
}                 
(a)main
(b)display
(c)maindisplay
(d)displaymain
(e)Compiler error
19. What will be output if you will compile and execute the following c
code?
void 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
20. What will be output if you will compile and execute the following c
       code?
void 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

No comments:

Post a Comment