21. What is the output of: printf("%d", 10 ? 0 ? 5 : 1 : 12);
Answer: C - This nested ternary operator evaluates to 1 because (10 is true → evaluates 0?5:1 → 0 is false → returns 1).
22. Which operator is used to access structure members through a pointer?
- a) . (dot)
- b) -> (arrow)
- c) :: (scope resolution)
- d) * (asterisk)
Answer: B - The arrow operator (->) is used to access structure members through a pointer.
23. What is the correct way to declare a function pointer that takes int and returns float?
- a) float *func(int);
- b) float (*func)(int);
- c) float (func*)(int);
- d) *float func(int);
Answer: B - The correct syntax is return_type (*pointer_name)(parameters).
24. What is the purpose of the 'typedef' keyword?
- a) To define new data types
- b) To create type aliases
- c) To allocate memory
- d) To declare variables
Answer: B - typedef is used to create new names (aliases) for existing types.
25. What is the output of: printf("%c", "Hello"[1]);
Answer: B - String literals are arrays, so "Hello"[1] accesses the second character 'e' (0-based index).
26. Which header file contains the definition of NULL?
- a) stdio.h
- b) stdlib.h
- c) stddef.h
- d) All of the above
Answer: D - NULL is defined in several standard headers including all three mentioned.
27. What is the size of an empty structure in C?
- a) 0 bytes
- b) 1 byte
- c) 4 bytes
- d) Compiler dependent
Answer: B - In C, an empty structure has size 1 byte to ensure unique addresses for instances.
28. Which of these is NOT a valid file opening mode?
Answer: D - "xa" is not a standard file opening mode in C.
29. What is the purpose of the '##' preprocessor operator?
- a) Stringizing
- b) Token pasting
- c) Concatenation
- d) Both b and c
Answer: D - The ## operator performs token pasting/concatenation during macro expansion.
30. What is the output of: printf("%d", ~5); (assuming 4-byte int)
Answer: C - The bitwise NOT of 5 (000...0101) is all 1s except the last 3 bits (111...1010), which is -6 in two's complement.
31. Which function is used to write formatted output to a string?
- a) printf()
- b) fprintf()
- c) sprintf()
- d) scanf()
Answer: C - sprintf() writes formatted output to a character array (string).
32. What is the purpose of the 'restrict' keyword in C?
- a) To restrict variable scope
- b) To optimize pointer access
- c) To make variables read-only
- d) To prevent memory leaks
Answer: B - 'restrict' tells the compiler that a pointer is the only way to access the pointed-to object, enabling optimizations.
33. What is the output of: printf("%d", sizeof("A"));
Answer: B - "A" is a string literal containing 'A' and '\0', so its size is 2 bytes.
34. Which of these is NOT a valid storage specifier?
- a) mutable
- b) register
- c) static
- d) extern
Answer: A - 'mutable' is a C++ keyword, not valid in C.
35. What is the purpose of the 'offsetof' macro?
- a) To find structure member offset
- b) To calculate array offsets
- c) To measure pointer distances
- d) To determine stack offsets
Answer: A - offsetof() (defined in stddef.h) returns the byte offset of a member within a structure.
36. What is the output of: printf("%d", 7 >> 1);
Answer: A - Right-shifting 7 (binary 0111) by 1 gives 3 (binary 0011).
37. Which function converts a string to a long integer?
- a) atoi()
- b) atol()
- c) atof()
- d) strtol()
Answer: D - strtol() provides more robust string-to-long conversion than atol().
38. What is the purpose of the 'va_list' type?
- a) To handle variable arguments
- b) To list variables
- c) To validate arguments
- d) To allocate argument memory
Answer: A - va_list is used with va_start, va_arg, and va_end to handle variable arguments in functions.
39. What is the output of: printf("%d", -1 >> 1);
- a) 0
- b) -1
- c) 1
- d) Implementation defined
Answer: D - Right-shifting negative numbers is implementation-defined in C.
40. Which of these is NOT a valid jump statement in C?
- a) goto
- b) break
- c) continue
- d) hop
Answer: D - "hop" is not a valid jump statement in C (the valid ones are goto, break, continue, and return).