Tuesday, March 24, 2009

C Aptitude Multiple Choice Questions and Answers

Q1. What will be the output of the following arithmetic expression ?

5+3*2%10-8*6

a) -37
b) -42
c) -32
d) -28

Q2. What will be the output of the following statement ?

int a=10; printf("%d &i",a,10);

a) error
b) 10
c) 10 10
d) none of these

Q3. What will be the output of the following statement ?

printf("%X%x%ci%x",11,10,'s',12);

a) error
b) basc
c) Bas94c
d) none of these

Q4. What will be the output of the following statements ?

int a = 4, b = 7,c; c = a = = b; printf("%i",c);

a) 0
b) error
c) 1
d) garbage value

Q 5. What will be the output of the following statements ?

int a = 5, b = 2, c = 10, i = a>b
void main()
{ printf("hello"); main(); }

a) 1
b) 2
c) infinite number of times
d) none of these

Q7. What will be the output of the following statements ?

int x[4] = {1,2,3}; printf("%d %d %D",x[3],x[2],x[1]);

a) 03%D
b) 000
c) 032
d) 321

Q8. What will be the output of the following statement ?

printf( 3 + "goodbye");

a) goodbye
b) odbye
c) bye
d) dbye


Q9. What will be the output of the following statements ?

long int a = scanf("%ld%ld",&a,&a); printf("%ld",a);

a) error
b) garbage value
c) 0
d) 2

Q10. What will be the output of the following program ?

#include
void main()
{ int a = 2;
switch(a)
{ case 1:
printf("goodbye"); break;
case 2:
continue;
case 3:
printf("bye");
}
}

a) error
b) goodbye
c) bye
d) byegoodbye



Q11. What will be the output of the following statements ?

int i = 1,j; j=i--- -2; printf("%d",j);

a) error
b) 2
c) 3
d) -3

Q12. What will be the output of following program ?

#include
main()
{
int x,y = 10;
x = y * NULL;
printf("%d",x);
}

a) error
b) 0
c) 10
d) garbage value

Q13. What will be the output of following statements ?

char x[ ] = "hello hi"; printf("%d%d",sizeof(*x),sizeof(x));

a) 88
b) 18
c) 29
d) 19

Q14. What will be the output of the following statements
?
int a=5,b=6,c=9,d; d=(ac?1:2):(c>b?6:8)); printf("%d",d);

a) 1
b) 2
c) 6
d) 8

Q15. What will be the output of the following statements ?

int i = 3;
printf("%d%d",i,i++);

a) 34
b) 43
c) 44
d) 33

Q16. What will be the output of the following program ?

#include
void main()
{
int a = 36, b = 9;
printf("%d",a>>a/b-2);
}

a) 9
b) 7
c) 5
d) none of these


Q17)
int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
What value does testarray[2][1][0] in the sample code above contain?

a) 11
b) 7
c) 5
d) 9

Q18)

void main()
{
int a=10,b=20;
char x=1,y=0;
if(a,b,x,y)
{
printf("EXAM");
}
}
What is the output?

1) XAM is printed
2) exam is printed
3) Compiler Error
4) Nothing is printed

Q19)

What is the output of the following code?
#include
void main()
{
int s=0;
while(s++<10)>
# define a 10
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
void foo()
{
#undef a
#define a 50
}

1) 10..10
2) 10..50
3) Error
4) 0

Q21)

main()
{
struct
{
int i;
}xyz;
(*xyz)->i=10;
printf("%d",xyz.i);
}
What is the output of this program?

1) program will not compile
2) 10
3) god only knows
4) address of I

Q22)
What would be the output of the following program?
#include
main()
{
char str[]="S\065AB";
printf("\n%d", sizeof(str));
}


1) 7
2) 6
3) 5
4) error

Q23)
What will be the value of `a` after the following code is executed
#define square(x) x*x
a = square(2+3)
1) 25
2) 13
3) 11
4) 10

Q24)
#include
void func()
{
int x = 0;
static int y = 0;
x++; y++;
printf( "%d -- %d\n", x, y );
}

int main()
{
func();
func();
return 0;
}

What will the code above print when it is executed?
1)
1 -- 1
1 -- 1
2)
1 -- 1
2 -- 1
3)
1 -- 1
2 -- 2
4)
1 -- 1
1 -- 2

Q25)

long factorial (long x)
{
????
return x * factorial(x - 1);
}
With what do you replace the ???? to make the function shown above return the correct answer?
1)
if (x == 0) return 0;
2)
return 1;
3)
if (x >= 2) return 2;
4)
if (x <= 1) return 1;

Q 26)

int y[4] = {6, 7, 8, 9};
int *ptr = y + 2; printf("%d\n", ptr[ 1 ] );

What is printed when the sample code above is executed?

1) 6
2) 7
3) 8
4) 9 .

Q27)

int i = 4;

switch (i)
{

default: ;
case 3:
i += 5;
if ( i == 8)
{
i++;
if (i == 9) break;
i *= 2;
}
i -= 4;
break;

case 8:
i += 5;
break;
}
printf("i = %d\n", i);

What will the output of the sample code above be?

1) i = 5
2) i = 8
3) i = 9
4) i = 10


Answers:
1.(a)-37
2.(d)none of them
3.(b)basc
4.(a)0
5.(c)infinite number of time
7.(c)032
8.(d)dbye
9.(b)garbage value
10.(a) error
11.(c) 3
12.(b)0
13.(d) 1 9
14.Error
15.(b)4 3
16.(a) 9
17.(a) 11
18.(d) nothing will be print
19.(3) Error
21.(2)10
22.(2) 6
23.(3) 11
24.(4)1..1,1..2
25.(4)if(x<=1)return 1;
26. (4) 9
27.(1) i=5

12 comments:

  1. i think..... Answer of 7,15,18,27 is wrong.


    check it.

    ReplyDelete
    Replies
    1. the 1st one is wrong answer ...the answer is -47

      Delete
  2. ya Sivakumar you are right... I have tried... answers of 7,15,18 and 27 are wrong...

    ReplyDelete
  3. Ques 27,15 is right..
    For Qeus 7 answer is :0 3 D

    ReplyDelete
  4. 9th one ans is 2......................,

    ReplyDelete
  5. answer of Q-3 is "basic" not "basc" check it...

    ReplyDelete
  6. Q5> answer is wrong
    correct answer : cannot call main() from within the program!!

    ReplyDelete
  7. Answer for Q7) is a...
    03%D

    ReplyDelete
  8. every answer is right checked with c compiler.

    ReplyDelete
  9. except 7 all are write...

    ReplyDelete