A Learning Platform

SUCCESS

Success = Discipline + Consistency + Sacrifice.
Discipline - in what you do.
Consistency - in what you do.
Sacrifice - for what you do.

                   -- Manjunatha C. P. --

C PROGRAMMING MCQ SET 8

1. Which of the following expressions is guaranteed to be evaluated left to right in C?
A) a + b + c
B) a && b
C) a * b + c
D) a = b = c

B) a && b

2. Which of the following best describes undefined behavior?
A) Behavior that is documented by compiler
B) Behavior that is implementation dependent
C) Behavior for which the C standard imposes no requirements
D) Behavior that always causes runtime error

C) Behavior for which the C standard imposes no requirements

3. What does the restrict keyword enable the compiler to do?
A) Disable pointer arithmetic
B) Assume pointers do not alias
C) Force pointer to be constant
D) Allocate memory on stack

B) Assume pointers do not alias

4. Which of the following is NOT guaranteed by the C standard?
A) sizeof(char) == 1
B) char uses at least 8 bits
C) Two’s complement representation
D) NULL compares equal to zero

C) Two’s complement representation

5. Which operator introduces a sequence point (classic terminology)?
A) ,
B) &&
C) ||
D) All of the above

D) All of the above

6. Which of the following is true about sizeof operator?
A) It is evaluated at runtime
B) It returns size in bits
C) It does not evaluate its operand (except VLAs)
D) It cannot be applied to expressions

C) It does not evaluate its operand (except VLAs)

7. Which of the following is a valid use of flexible array member?
A) int a[];
B) struct S { int n; int a[]; };
C) struct S { int a[0]; };
D) struct S { int a[1]; };

B) struct S { int n; int a[]; };

8. What happens if longjmp() is called without a prior setjmp()?
A) Program restarts
B) Compilation error
C) Undefined behavior
D) Stack overflow

C) Undefined behavior

9. Which function is async-signal-safe according to C/POSIX standards?
A) printf()
B) malloc()
C) free()
D) write()

D) write()

10. Which of the following is true about volatile sig_atomic_t?
A) It is thread-safe
B) It can be accessed atomically in signal handlers
C) It is stored in register
D) It disables interrupts

B) It can be accessed atomically in signal handlers

11. Which C standard first introduced inline keyword?
A) C89
B) C90
C) C99
D) C11

C) C99

12. Which of the following guarantees zero initialization?
A) malloc()
B) calloc()
C) realloc()
D) alloca()

B) calloc()

13. Which statement about pointer comparison is correct?
A) Pointers to different objects can always be compared
B) Only NULL pointers can be compared
C) Comparison is defined only within same array object
D) Pointer comparison is implementation defined

C) Comparison is defined only within same array object

14. Which of the following functions can detect buffer overflow?
A) strcpy()
B) strncpy()
C) gets()
D) None of the above

D) None of the above

15. Which operator has the lowest precedence in C?
A) ,
B) =
C) ||
D) &&

A) ,

16. Which header defines offsetof macro?
A) stdlib.h
B) stddef.h
C) string.h
D) limits.h

B) stddef.h

17. What does the macro __LINE__ expand to?
A) File name
B) Line number in source file
C) Compilation time
D) Function name

B) Line number in source file

18. Which of the following is NOT a valid storage duration?
A) Automatic
B) Static
C) Thread
D) Dynamic

C) Thread

19. Which of the following is guaranteed to be lock-free?
A) int
B) long
C) atomic_int
D) volatile int

C) atomic_int

20. What does the function strncat() ensure?
A) Always null-terminated result
B) Buffer overflow prevention
C) Appends fixed number of characters
D) Automatic memory allocation

C) Appends fixed number of characters

21. Which feature was introduced in C11?
A) Variable Length Arrays
B) _Static_assert
C) inline
D) restrict

B) _Static_assert

22. Which of the following correctly describes trap representations?
A) Always zero
B) Valid bit patterns for all types
C) Certain bit patterns causing undefined behavior
D) Compiler warnings only

C) Certain bit patterns causing undefined behavior

23. Which function is guaranteed to flush output buffer?
A) printf()
B) puts()
C) fflush(stdout)
D) scanf()

C) fflush(stdout)

24. What does the expression (void)0 commonly represent?
A) Null pointer
B) Empty statement / do-nothing macro
C) Integer zero
D) Compiler directive

B) Empty statement / do-nothing macro

25. Which of the following best characterizes C memory model?
A) Object-oriented
B) Strictly sequential
C) Flat address space with objects
D) Virtual memory dependent

C) Flat address space with objects