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 7 8 9 10 Last »
« Previous Page Next Page »

161. What is the output of: printf("%d", (int(*)[2]){1,2}[0][1]);

  • a) 1
  • b) 2
  • c) Compilation error
  • d) Undefined behavior
Answer: B - This compound literal creates a pointer to array[2] and accesses element [0][1].

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

  • a) atomic_compare_exchange_strong()
  • b) atomic_compare_exchange_weak()
  • c) atomic_compare_swap()
  • d) (No incorrect options - all are valid)
Answer: C - atomic_compare_swap() doesn't exist (correct are compare_exchange_strong/weak).

163. What is the purpose of the 'mtx_timedlock()' function?

  • a) Lock mutex with timeout
  • b) Lock mutex recursively
  • c) Initialize timed mutex
  • d) Destroy mutex
Answer: A - mtx_timedlock() attempts to lock mutex with timeout.

164. 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=2, then 1^2=3.

165. Which function is used to query floating-point sign in C99?

  • a) signbit()
  • b) fp_sign()
  • c) fsign()
  • d) getsign()
Answer: A - signbit() macro from math.h tests floating-point sign.

166. What is the value of: (int(*)[2]){1,2} + 1

  • a) 1
  • b) 2
  • c) Pointer to next array
  • d) Compilation error
Answer: C - Pointer arithmetic advances by sizeof(int[2]) bytes.

167. Which of these is NOT a valid C11 thread error code?

  • a) thrd_nomem
  • b) thrd_timedout
  • c) thrd_busy
  • d) thrd_locked
Answer: D - thrd_locked doesn't exist (correct are nomem/timedout/busy).

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

  • a) 1
  • b) 3
  • c) 5
  • d) 7
Answer: B - * first: 2*3=6, then 1+6-4=3.

169. What is the purpose of the 'mtx_plain' constant?

  • a) Non-recursive mutex
  • b) Recursive mutex
  • c) Timed mutex
  • d) Shared mutex
Answer: A - mtx_plain creates non-recursive mutex (vs mtx_recursive).

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

  • a) 0
  • b) 1
  • c) Undefined behavior
  • d) Implementation defined
Answer: B - 1<<30 creates 0x40000000, >>30 brings it back to 1.

171. Which function is used to find wide character in memory block?

  • a) wmemchr()
  • b) wchr()
  • c) wfind()
  • d) wstrchr()
Answer: A - wmemchr() searches for wide character in memory.

172. What is the value of: (int(*)[2]){1,2}[0][0] = 3

  • a) 1
  • b) 2
  • c) 3
  • d) Compilation error
Answer: C - Array elements from compound literals are modifiable.

173. Which of these is NOT a valid C11 mutex type?

  • a) mtx_plain
  • b) mtx_recursive
  • c) mtx_timed
  • d) mtx_shared
Answer: D - mtx_shared doesn't exist (correct are plain/recursive/timed).

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

  • a) 2
  • b) 3
  • c) 5
  • d) Compilation error
Answer: C - 1 is true → evaluates 2+3=5 (ternary has lower precedence than +).

175. What is the purpose of the 'mtx_recursive' constant?

  • a) Recursive mutex
  • b) Non-recursive mutex
  • c) Timed mutex
  • d) Shared mutex
Answer: A - mtx_recursive creates mutex that can be locked multiple times by same thread.

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

  • a) 8
  • b) 16
  • c) 32
  • d) 64
Answer: C - Left-associative: (1<<3)=8, then 8<<2=32.

177. Which function is used to compare wide character memory blocks?

  • a) wmemcmp()
  • b) wcmp()
  • c) wmcmp()
  • d) wstrcmp()
Answer: A - wmemcmp() compares wide character memory blocks.

178. What is the value of: (int(*)[2]){1,2}[0][1] = 3

  • a) 1
  • b) 2
  • c) 3
  • d) Compilation error
Answer: C - Array elements from compound literals are modifiable.

179. Which of these is NOT a valid C11 mutex initialization flag?

  • a) mtx_plain
  • b) mtx_timed
  • c) mtx_shared
  • d) mtx_recursive
Answer: C - mtx_shared doesn't exist (correct are plain/timed/recursive).

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

  • a) 3
  • b) 5
  • c) 7
  • d) Compilation error
Answer: C - 0 is false → evaluates 3+4=7 (ternary has lower precedence than +).
« First 7 8 9 10 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.