1. What is the output of the following code?
int main() {
int a = 5;
printf("%d", a++ + ++a);
return 0;
}
a) 10 b) 11 c) 12 d) Undefined Behavior
Answer: d) Undefined Behavior
2. What does the following print?
int main() {
int i = 0;
for(i = 0; i < 3; i++) {
static int x = 0;
x++;
printf("%d ", x);
}
return 0;
}
a) 1 2 3 b) 0 1 2 c) 3 3 3 d) 1 1 1
Answer: a) 1 2 3
3. Choose correct output:
int main() {
int x = 10;
int *p = &x;
*p = *p + 2;
printf("%d", x);
return 0;
}
a) 10 b) 12 c) 0 d) Address of x
Answer: b) 12
4. Which of the following is correct for 'char *p = "CDAC";'?
a) p points to a string literal b) p can be modified safely
c) p is a char array d) Compilation error
Answer: a) p points to a string literal
5. Result of:
int main() {
int a = 0;
if (a = 5)
printf("True");
else
printf("False");
return 0;
}
a) True b) False c) Error d) None
Answer: a) True
6. What is the result of this code?
int main() {
int x = 3;
int y = ++x + x++;
printf("%d", y);
return 0;
}
a) 7 b) 8 c) 9 d) Undefined
Answer: d) Undefined
7. Output?
int main() {
char s[] = "Hello";
printf("%d", sizeof(s));
return 0;
}
a) 5 b) 6 c) 4 d) Undefined
Answer: b) 6
8. What is the result?
int main() {
char c = 255;
printf("%d", c);
return 0;
}
a) 255 b) -1 c) 127 d) Implementation defined
Answer: d) Implementation defined
9. Predict the output:
int main() {
int arr[] = {10, 20, 30};
printf("%d", 2[arr]);
return 0;
}
a) 10 b) 20 c) 30 d) Error
Answer: c) 30
10. Which of the following is valid?
int main() {
const int x = 5;
int *p = &x;
*p = 10;
printf("%d", x);
return 0;
}
a) 5 b) 10 c) Error d) Undefined behavior
Answer: d) Undefined behavior