read this code: C Programming MCQ Tests | PCBooks - Master C Language Online

C - Programming MCQ Questions and Answers

Test your knowledge of Microsoft Word with these interactive multiple-choice questions.

« First 6 7 8 9 Last »
« Previous Page Next Page »

121. What is the output of: printf("%d", (struct {int x;}){1}.x);

  • a) 0
  • b) 1
  • c) Compilation error
  • d) Undefined behavior
Answer: B - This compound literal creates a struct with x=1 and accesses it.

122. Which of these is NOT a valid C11 atomic operation?

  • a) atomic_load()
  • b) atomic_store()
  • c) atomic_modify()
  • d) atomic_exchange()
Answer: C - atomic_modify() doesn't exist (correct are load/store/exchange/etc).

123. What is the purpose of the 'cnd_init()' function?

  • a) Initialize condition variable
  • b) Create thread
  • c) Allocate memory
  • d) Signal condition
Answer: A - cnd_init() initializes a condition variable for thread synchronization.

124. What is the output of: printf("%d", 1 | 2 ^ 3);

  • a) 0
  • b) 1
  • c) 2
  • d) 3
Answer: D - ^ has higher precedence: 2^3=1, then 1|1=3.

125. Which function is used to query subnormal numbers in C99?

  • a) issubnormal()
  • b) fpclassify()
  • c) isnormal()
  • d) isfinite()
Answer: A - issubnormal() macro from math.h tests for subnormal numbers.

126. What is the value of: (struct {int x;}){1} = (struct {int x;}){2}

  • a) 1
  • b) 2
  • c) Lvalue required error
  • d) Compilation error
Answer: C - Compound literals are not modifiable lvalues.

127. Which of these is NOT a valid C11 thread cancellation function?

  • a) thrd_cancel()
  • b) thrd_detach()
  • c) thrd_exit()
  • d) thrd_join()
Answer: A - thrd_cancel() doesn't exist (C11 threads don't support cancellation).

128. What is the output of: printf("%d", 1 + 2 % 3 * 4);

  • a) 1
  • b) 3
  • c) 9
  • d) 12
Answer: C - % and * same precedence: 2%3=2, 2*4=8, then 1+8=9.

129. What is the purpose of the 'tss_create()' function?

  • a) Create thread-specific storage key
  • b) Create thread
  • c) Allocate memory
  • d) Initialize mutex
Answer: A - tss_create() creates a thread-specific storage key.

130. What is the output of: printf("%d", 1 << 32 >> 32); (32-bit int)

  • a) 0
  • b) 1
  • c) Undefined behavior
  • d) Implementation defined
Answer: C - Shifting by >= width of type is undefined behavior.

131. Which function is used to get length of wide character string?

  • a) wcslen()
  • b) wslen()
  • c) wlen()
  • d) wstrlen()
Answer: A - wcslen() returns length of wide character string.

132. What is the value of: (struct {int x;}*)0 + 1

  • a) 0
  • b) 1
  • c) sizeof(struct) bytes
  • d) Compilation error
Answer: C - Pointer arithmetic advances by sizeof(struct) bytes.

133. Which of these is NOT a valid C11 once_flag function?

  • a) call_once()
  • b) once_flag_init()
  • c) ONCE_FLAG_INIT
  • d) (No incorrect options - all are valid)
Answer: B - once_flag_init() doesn't exist (use ONCE_FLAG_INIT macro).

134. What is the output of: printf("%d", 1 ? 2 : 3 + 4);

  • a) 2
  • b) 3
  • c) 7
  • d) Compilation error
Answer: A - Ternary has higher precedence than +: 1?2:(3+4) → 1 is true → 2.

135. What is the purpose of the 'tss_set()' function?

  • a) Set thread-specific value
  • b) Set thread priority
  • c) Set mutex attribute
  • d) Set condition variable
Answer: A - tss_set() associates value with thread-specific key.

136. What is the output of: printf("%d", 1 << 1 << 1 << 1 << 1);

  • a) 4
  • b) 8
  • c) 16
  • d) 32
Answer: D - Left-associative: ((((1<<1)<<1)<<1)<<1 → 1→2→4→8→16.

137. Which function is used to compare wide character strings case-insensitively?

  • a) wcscmp()
  • b) wcsicmp()
  • c) wcscasecmp()
  • d) wcsncmp()
Answer: C - wcscasecmp() is POSIX standard (wcsicmp() is common but non-standard).

138. What is the value of: (struct {int x;}){1}.x = 2

  • a) 1
  • b) 2
  • c) Lvalue required error
  • d) Compilation error
Answer: B - Struct members from compound literals are modifiable (value becomes 2).

139. Which of these is NOT a valid C11 thread timing function?

  • a) thrd_sleep_for()
  • b) thrd_sleep_until()
  • c) thrd_delay()
  • d) thrd_yield()
Answer: C - thrd_delay() doesn't exist (correct are sleep_for/sleep_until/yield).

140. What is the output of: printf("%d", 0 ? 1 : 0 ? 2 : 3);

  • a) 1
  • b) 2
  • c) 3
  • d) 4
Answer: C - Right-associative: 0?1:(0?2:3) → 0 is false → 3.
« First 6 7 8 9 Last »
« Previous Page Next Page »

Learn Computer Skills with PCBooks

Master computer skills with PCBooks! Explore interactive tutorials, MCQ tests, and online exams for programming, web development, and IT fundamentals. Perfect for beginners and advanced learners.

Online MCQ Tests for Programming

Practice programming MCQ questions and improve your coding skills with our online quizzes. Whether you're learning Python, Java, or C programming, PCBooks has you covered.

Free Web Development Tutorials

Learn HTML, CSS, and JavaScript with our free web development tutorials. Test your knowledge with interactive quizzes and online exams.