100% found this document useful (1 vote)
651 views15 pages

C Test Questions and Answers PDF

This document contains 20 multiple choice questions about C programming. Each question has a code snippet and 5 possible answers. The correct answers are provided at the end. The questions cover topics like conditional compilation, operators, data types, structures, unions, and more. The document is from a blog that provides C programming questions and is intended as a practice test for a total of 60 marks.

Uploaded by

Vikas Bakoliya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
651 views15 pages

C Test Questions and Answers PDF

This document contains 20 multiple choice questions about C programming. Each question has a code snippet and 5 possible answers. The correct answers are provided at the end. The questions cover topics like conditional compilation, operators, data types, structures, unions, and more. The document is from a blog that provides C programming questions and is intended as a practice test for a total of 60 marks.

Uploaded by

Vikas Bakoliya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

8/25/2011

C PROGRAMMING QUESTIONS AND


C ANSWER

http://cquestionbank.blogspot.com | Ritesh kumar


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 a=0;
#if (a==0)
printf("Equal");
#else if
printf("Not equal");
#endif
return 0;
}

(A) Equal
(B) Not equal
(C) null
(D) Garbage
(E) Compilation error

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

#include<stdio.h>
int main(){
for(;NULL;)
Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 2
printf("cquestionbank");
return 0;
}

(A) c
(B) bank
(C) cquestionbank
(D) Infinite loop
(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) 0
(B) 1
(C) 154
(D) 155
(E) Compilation error

4.

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


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

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

(A) 7 13 7
(B) 13 13 13
(C) 13 13 5
(D) 6 13 5
(E) Compilation error

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

#include<stdio.h>
int main(){
Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 4
int a[]={0,1,2,3,4,5,6,7,8,9,10};
int i=0,num;
num=a[++i+a[++i]]+a[++i];
printf("%d",num);
return 0;

(A) 6
(B) 7
(C) 8
(D) 9
(E) Compilation error

6.
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;

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

(A) 2 0
(B) 7 1
(C) 17 0
(D) 2 1
Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 5
(E) Compilation error

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

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

(A) 9
(B) 10
(C) 32
(D) 34
(E) Compilation error

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

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

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


Page 6
(A) 65
(B) -65
(C) -a
(D) -97
(E) Compilation error

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

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

(A) 5 4
(B) -4 4
(C) -5 4
(D) -4 5
(E) Compilation error

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

#include<stdio.h>
int main(){
int num,a=10;
Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 7
num=a&&0+ +-1&&a;
printf("%d %d",num,a);
return 0;

(A) 1 1
(B) 0 0
(C) 1 10
(D) 0 10
(E) Compilation error

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

#include<stdio.h>
int main(){
int x,y,z;
y=(x=1,y=2,z=3);
printf("%d %d %d",x,y,z);
return 0;

(A) 1 2 3
(B) 1 1 3
(C) 1 3 3
(D) 1 0 3
(E) Compilation error

12.

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


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

#include<stdio.h>
#include<conio.h>
int main(){
int t,a=5,b=10,c=15;
t=(++a&&++b,++a),++a||++c;
printf("%d %d %d %d",t,a,b,c);
return 0;

(A) 7 8 11 15
(B) 6 7 10 14
(C) 1 8 10 15
(D) 6 18 11 15
(E) Compilation error

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

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

}
int change(){
a=0;
return 0;
}
Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 9
(A) 0
(B) 5.000000
(C) 0.000000
(D) 1.000000
(E) Compilation error

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

#include<stdio.h>
typedef struct cquestionbank{
int num;
struct cquestionbank **p;
struct cquestionbank ***q;
}cqb;
int main(){
static cqb *var1,**var2;
cqb temp={5,&var1,&var2};
var2=&var1;
var1->num=25;
printf("%d %d ",**(temp.q),***(temp.q));
return 0;
}

(A) 0 5
(B) 0 25
(C) 5 25
(D) 25 5
(E) Compilation error

15.
Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 10
What will be output if you will execute following c
code?

#include<stdio.h>
union cqbu{
int a;
char b;
};
struct cqbs{
int a;
char b;
};
int main(){
union cqbu u={25};
struct cqbs *ps=(struct cqbs *)&u;
union cqbu *pu=(union cqbu *)&u;
printf("%d %d\n",ps->a,ps->b);
printf("%d %d\n",pu->a,pu->b);
return 0;
}

(A) 25 0
25 25

(B) 25 25
25 0

(C) 0 0
25 25

(D) 25 25
25 25
(E) Compilation error

16.

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


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

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

(A) 0
(B) 0.000000
(C) 1.000000
(D) 3.000000
(E) Compilation error

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

#include<stdio.h>
int main(){
float x;
x=(int)(int)2.5+5.8f;
printf("%f",x);
return 0;
}

(A) 7.000000
(B) 7.800000
(C) 8.000000
(D) 8.100000
(E) Compilation error

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


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

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

(A) 0.000000
(B) 1.000000
(C) 3.000000
(D) 3.300000
(E) Compilation error

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

#include<stdio.h>
#include <string.h>
typedef struct stu1{
int roll;
char *name;
double marks;
}STU1;
typedef struct stu2{
int roll;
char *name;
double marks;
Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 13
}STU2;
int main(){
STU1 s1={25,"Rohit",87.43},*p1;
static STU2 *p2;
p1=&s1;
memccpy(p2,p1,'\0',sizeof(STU1));
printf("Roll : %d\n",p2->roll);
printf("Name : %s\n",p2->name);
printf("Marks : %lf",p2->marks);
return 0;

Roll : 25
(A) Name : (null)
Marks : 0.000000

Roll : 25
(B) Name : rohit
Marks : 0.000000

Roll : 25
(C) Name : rohit
Marks : 87.430000

Roll : 0
(D) Name : (null)
Marks : 0.000000
(E) Compilation error

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

#include<stdio.h>
#define value 30
Copyright@ritesh kumar: http://cquestionbank.blogspot.com/
Page 14
int main(){
#if max
printf("Defined");
#else
printf("Not defined");
#endif
return 0;
}
(A) Defined
(B) Not defined
(C) null
(D) Run time error
(E) Compilation error

1. (E)
2. (C)
3. (E)
4. (A)
5. (D)
6. (B)
7. (D)
8. (D)
9. (C)
10. (C)
11. (C)
12. (A)
13. (D)
14. (B)
15. (A)
16. (C)
17. (B)
18. (A)
19. (A)
20. (B)

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


Page 15

You might also like