C Programming MCQs for Embedded Interview - Set 1
Q1. What will be the output of the following code?
int a = 5;
printf("%d %d %d\n", a++, ++a, a);
A) 5 6 6
B) 6 6 6
C) 5 5 5
D) Undefined behavior
Answer: D - Undefined behavior due to multiple modifications of 'a' between sequence points.
Q2. What is the output of this program?
int arr[] = {10, 20, 30};
printf("%d\n", *(arr + 1));
A) 10
B) 20
C) 30
D) Garbage value
Answer: B - Pointer arithmetic accesses second element.
Q3. What is the value of 'x' after this code?
int x = 5;
int *p = &x;
*p = 10;
A) 0
B) 5
C) 10
D) Address of x
Answer: C - The value at x is updated via pointer.
Q4. What does the following function return for fun(3)?
int fun(int n) { if(n == 0) return 1; else return n * fun(n - 1); }
A) 3
B) 6
C) 9
D) 1
Answer: B - Recursive factorial of 3 is 6.
Q5. What is the output?
char str[] = "EmbedUR";
printf("%c\n", *(str + 4));
A) E
B) b
C) d
D) U
Answer: C - *(str + 4) = fifth character = 'd'.
Q6. Which of these is a correct way to declare a pointer to a function?
A) int *f();
B) int (*f)();
C) int f*();
D) int &(f)();
Answer: B - Pointer to function returning int.
Q7. Which keyword tells the compiler that a variable may be changed outside the program flow?
A) const
B) register
C) volatile
D) extern
Answer: C - 'volatile' used for memory-mapped I/O, ISRs.
Q8. What is the size of int arr[10]; on a 32-bit system?
A) 10
B) 40
C) 20
D) 4
Answer: B - 10 integers × 4 bytes each = 40 bytes.
Q9. What is the output?
int a = 1;
int b = a++ + ++a;
printf("%d\n", b);
A) 3
B) 4
C) 5
D) Undefined
Answer: D - Undefined behavior due to multiple increments of 'a'.
Q10. What is printed?
void func() { static int count = 0; count++; printf("%d ", count); }
func(); func(); func();
A) 1 2 3
B) 1 1 1
C) 0 1 2
D) Garbage
Answer: A - Static variable retains value between calls.