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

21. What is the output of: printf("%d", 10 ? 0 ? 5 : 1 : 12);

  • a) 10
  • b) 0
  • c) 1
  • d) 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]);

  • a) H
  • b) e
  • c) l
  • d) o
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?

  • a) r+
  • b) wb
  • c) a+
  • d) xa
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)

  • a) 5
  • b) -5
  • c) -6
  • d) 6
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"));

  • a) 1
  • b) 2
  • c) 4
  • d) 8
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);

  • a) 3
  • b) 4
  • c) 7
  • d) 14
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).
« First 1 2 3 4 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.