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 2 3 4 5 Last »
« Previous Page Next Page »

41. What is the output of: printf("%d", sizeof(main()));

  • a) 2
  • b) 4
  • c) Compilation error
  • d) Runtime error
Answer: C - sizeof cannot be applied to function calls, only to types or expressions.

42. Which of these is NOT a valid C standard header file?

  • a) stdalign.h
  • b) stdnoreturn.h
  • c) stdthread.h
  • d) stdatomic.h
Answer: C - stdthread.h is not a standard C header (C11 added threads.h instead).

43. What is the purpose of the _Generic keyword in C11?

  • a) Generic programming
  • b) Memory allocation
  • c) Error handling
  • d) Thread synchronization
Answer: A - _Generic provides type-generic expressions (similar to function overloading).

44. What is the output of: printf("%d", 1 && -1);

  • a) 0
  • b) 1
  • c) -1
  • d) Undefined
Answer: B - Logical AND returns 1 (true) since both operands are non-zero.

45. Which function properly compares two strings case-insensitively?

  • a) strcmp()
  • b) strncmp()
  • c) stricmp()
  • d) strcasecmp()
Answer: D - strcasecmp() is the POSIX standard (stricmp() is common but non-standard).

46. What is the value of: 5["abcdef"]

  • a) 'a'
  • b) 'e'
  • c) 'f'
  • d) Compilation error
Answer: C - Array indexing is commutative in C (equivalent to "abcdef"[5]).

47. Which qualifier prevents compiler reordering of operations?

  • a) const
  • b) volatile
  • c) static
  • d) atomic
Answer: B - volatile tells compiler not to optimize accesses to the variable.

48. What is the output of: printf("%d", 7 & 3);

  • a) 1
  • b) 3
  • c) 5
  • d) 7
Answer: B - Bitwise AND of 7 (0111) and 3 (0011) is 3 (0011).

49. Which of these is NOT a valid C11 feature?

  • a) Anonymous structures
  • b) Type-generic macros
  • c) Lambda expressions
  • d) Static assertions
Answer: C - Lambda expressions were not added in C11 (they exist in C++).

50. What is the purpose of the 'aligned_alloc' function?

  • a) Allocate aligned memory
  • b) Allocate array memory
  • c) Allocate thread memory
  • d) Allocate atomic memory
Answer: A - aligned_alloc(size_t alignment, size_t size) allocates memory with specific alignment.

51. What is the output of: printf("%d", !!10);

  • a) 0
  • b) 1
  • c) 10
  • d) -1
Answer: B - First !10 gives 0, then !0 gives 1 (double negation converts to boolean).

52. Which function should be used to safely copy strings?

  • a) strcpy()
  • b) strncpy()
  • c) memcpy()
  • d) snprintf()
Answer: D - snprintf() is safest as it guarantees null-termination and bounds checking.

53. What is the value of: (int[]){1,2,3}[1]

  • a) 1
  • b) 2
  • c) 3
  • d) Compilation error
Answer: B - This is a compound literal accessing the second element (index 1).

54. Which of these is NOT a valid C99 feature?

  • a) Variable-length arrays
  • b) Designated initializers
  • c) Range-based for loops
  • d) Flexible array members
Answer: C - Range-based for loops are a C++ feature, not in C.

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

  • a) 1
  • b) 2
  • c) 3
  • d) 4
Answer: D - Addition has higher precedence than shift, so 1 << (1+1) = 1<<2 = 4.

56. Which function converts a wide character string to a multibyte string?

  • a) wctomb()
  • b) wcstombs()
  • c) mbtowc()
  • d) mbstowcs()
Answer: B - wcstombs() converts wide character strings to multibyte strings.

57. What is the purpose of the 'static_assert' declaration?

  • a) Runtime assertion
  • b) Compile-time assertion
  • c) Debug assertion
  • d) Thread assertion
Answer: B - static_assert (from C11) performs compile-time assertion checking.

58. What is the output of: printf("%d", 0x10 == 16);

  • a) 0
  • b) 1
  • c) 16
  • d) Compilation error
Answer: B - 0x10 is hexadecimal for 16, so the comparison is true (1).

59. Which of these is NOT a valid C floating-point constant?

  • a) 1.0e-5
  • b) 0x1.0p-5
  • c) 1.0d-5
  • d) 1.0F
Answer: C - C doesn't use 'd' suffix (it's from other languages), 'f' or 'F' is used instead.

60. What is the purpose of the 'fenv.h' header?

  • a) File environment
  • b) Floating-point environment
  • c) Function environment
  • d) Format environment
Answer: B - fenv.h provides access to floating-point environment and control modes.
« First 2 3 4 5 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.