You are on page 1of 15

Copyright@ritesh kumar: http://cquestionbank.blogspot.

com/[Type text] Page 1



8/25/2011


http://cquestionbank.blogspot.com | Ritesh kumar
C
C PROGRAMMING QUESTIONS AND
ANSWER

Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 2

Total marks : 60
For each correct answer : +3
For each incorrect answer: -1
Total time: 60 minutes


1.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
int i;
for(i=0;i<5;i++){
int i=10;
printf(" %d",i);
i++;
}
return 0;
}

(A) 10 11 12 13 14

(B) 10 10 10 10 10

(C) 0 1 2 3 4

(D) Infinite loop

(E) Compilation error



2.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){

Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 3

register a,b,x;
scanf("%d %d",&a,&b);
x=a+~b;
printf("%d",x);
return 0;
}

(A) Output will depend upon user input

(B) 0

(C) Output will difference of a and b

(D)

Output will addition of a and b

(E) Compilation error



3.
What will be output if you will execute following c
code?

#include<stdio.h>
auto int a=5;
int main(){
int x;
x=~a+a&a+a<<a;
printf("%d",x);
return 0;
}

(A) 5

(B) 0

(C) 1

(D) 153

(E) Compilation error


Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 4



4.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
register int a,b;
int c;
scanf("%d%d",&a,&b);
c=~a + ~b + ++a + b++;
printf(" %d",c);
return 0;

}

//User input is: 1 2
(A) -1

(B) 0

(C) 1

(D) 2

(E) Compilation error



5.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
int arr[3]={10,20,30};
int x=0;
x=++arr[++x]+ ++x+arr[--x];

Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 5

printf("%d ",x);
return 0;

}

(A)

23

(B) 43

(C)

22

(D) 44

(E) Compilation error



6.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
int a[]={10,20,30,40};
int i=3,x;
x=1*a[--i]+2*a[--i]+3*a[--i];
printf("%d",x);
return 0;

}

(A) 60

(B) 50

(C) 40

(D) 30

(E) Compilation error


Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 6



7.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
static int a[][2][3]={0,1,2,3,4,5,6,7,8,9,10,11,12}
;
int i=-1;
int d;
d=a[i++][++i][++i];
printf("%d",d);
return 0;

}

(A) 9

(B) 10

(C) 11

(D) 12

(E) Compilation error



8.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
int i=3,val;
val=sizeof (f(i)+ +f(i=1)+ +f(i-1));
printf("%d %d",val,i);
return 0;

Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 7


}
int f(int num){
return num*5;
}

(A) 2 2

(B) 3 3

(C)

2 3

(D) 15 0

(E) Compilation error



9.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
int x,a=3;
x=+ +a+ + +a+ + +5;
printf("%d %d",x,a);
return 0;

}

(A) 10 3

(B) 11 3

(C) 10 5

(D) 11 3

(E) Compilation error


Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 8



10.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
int num,i=0;
num=-++i+ ++-i;
printf("%d",num);
return 0;

}

(A) 0

(B) 1

(C) -2

(D) 2

(E) Compilation error



11.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
int num,a=5;
num=-a--+ +++a;
printf("%d %d",num,a);
return 0;

}


Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 9

(A)

1 5

(B) -1 6

(C) 1 6

(D) 0 5

(E) Compilation error



12.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
int num,a=15;
num=- - - -a--;
printf("%d %d",num,a);
return 0;

}

(A) 15 15

(B) 14 14

(C)

14 15

(D) 15 14

(E) Compilation error



13.
What will be output if you will execute following c
code?

#include<stdio.h>

Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 10

int main(){
int x,a=2;
x=++a,++a,a++;
printf("%d %d",x,a);
return 0;

}

(A) 5 5

(B) 3 5

(C) 4 5

(D) 5 4

(E) Compilation error



14.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
int x,i=2;
x=~-!++i;
printf("%d",x);
return 0;

}

(A) -2

(B) -1

(C) 0

(D) 1

(E) Compilation error


Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 11



15.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
static double *p,*q,*r,*s,t=5.0;
double **arr[]={&p,&q,&r,&s};
int i;
*p=*q=*r=*s=t;
for(i=0;i<4;i++)
printf("%.0f ",**arr[i]);
return 0;
}

(A) 5 5 5 5 5

(B) 5 6 7 8 9

(C) 5 4 3 2 1

(D) Infinte loop

(E) Compilation error



16.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
float x;
x=0.35==3.5/10;
printf("%f",x);
return 0;
}

Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 12


(A) 0.000000

(B) 1.000000

(C) 0.350000

(D) 3.500000

(E) Compilation error



17.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
int arr[]={6,12,18,24};
int x=0;
x=arr[1]+(arr[1]=2);
printf("%d",x);
return 0;

}

(A)

4

(B) 8

(C) 14

(D) 14

(E) Compilation error



18.
What will be output if you will execute following c
code?


Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 13

#include<stdio.h>
int main(){
int a=1,x;
x=sq(++a)+sq(a++)+sq(a++);
printf("%d",x);
return 0;

}
int sq(int num){
return num*num;
}

(A) 15

(B) 16

(C) 17

(D) 18

(E) Compilation error



19.
What will be output if you will execute following c
code?
#include<stdio.h>
int main(){
printf("%c",*"abcde");
return 0;

}

(A) acbcd

(B) e

(C) a

(D) null

(E) Compilation error


Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 14



20.
What will be output if you will execute following c
code?

#include<stdio.h>
int main(){
printf("%d","abcde"-"abcde");
return 0;

}

(A) 0

(B) -1

(C) 1

(D) Garbage

(E) Compilation error





1. (B)
2. (E)
3. (E)
4. (E)
5. (B)
6. (A)
7. (B)
8. (C)
9. (D)

Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 15

10. (B)
11. (D)
12. (D)
13. (B)
14. (B)
15. (A)
16. (A)
17. (A)
18. (C)
19. (C)
20. (D)

You might also like