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 »

1. What is the correct syntax to declare a pointer in C?

  • a) int ptr*;
  • b) *int ptr;
  • c) int *ptr;
  • d) ptr int*;
Answer: C - The correct syntax is data type followed by asterisk then pointer name (int *ptr).

2. Which of these is NOT a valid C keyword?

  • a) volatile
  • b) register
  • c) string
  • d) typedef
Answer: C - "string" is not a keyword in C, though it can be implemented using character arrays.

3. What is the output of sizeof(int) on a 32-bit system?

  • a) 2 bytes
  • b) 4 bytes
  • c) 8 bytes
  • d) Compiler dependent
Answer: B - On 32-bit systems, sizeof(int) is typically 4 bytes.

4. Which operator has the highest precedence in C?

  • a) &&
  • b) ||
  • c) ()
  • d) =
Answer: C - Parentheses () have the highest precedence in C.

5. What is the purpose of the #include directive?

  • a) To link libraries
  • b) To include header files
  • c) To define macros
  • d) To declare variables
Answer: B - #include is used to include the contents of header files in the source code.

6. Which function is used to allocate memory dynamically?

  • a) malloc()
  • b) calloc()
  • c) realloc()
  • d) All of the above
Answer: D - All these functions are used for dynamic memory allocation in C.

7. What is the default return type of a function in C?

  • a) void
  • b) int
  • c) float
  • d) char
Answer: B - If no return type is specified, the function defaults to returning int.

8. Which of these is NOT a storage class in C?

  • a) auto
  • b) register
  • c) dynamic
  • d) static
Answer: C - "dynamic" is not a storage class in C. The storage classes are auto, register, static, and extern.

9. What is the correct way to initialize an array in C?

  • a) int arr[] = {1, 2, 3};
  • b) int arr[3] = {1, 2, 3};
  • c) int arr[3]; arr = {1, 2, 3};
  • d) Both a and b
Answer: D - Both a and b are correct ways to initialize an array in C.

10. What does the 'break' statement do in a switch case?

  • a) Terminates the program
  • b) Exits the switch statement
  • c) Continues to the next case
  • d) Restarts the switch statement
Answer: B - The break statement exits the switch statement, preventing fall-through to other cases.

11. What is the output of: printf("%d", 5 + 2 * 3);

  • a) 21
  • b) 11
  • c) 15
  • d) 17
Answer: B - Due to operator precedence, multiplication is done first (2*3=6) then addition (5+6=11).

12. Which header file is required for using printf() and scanf()?

  • a) conio.h
  • b) math.h
  • c) stdio.h
  • d) stdlib.h
Answer: C - stdio.h (Standard Input Output header file) contains declarations for printf() and scanf().

13. What is the purpose of the 'void' keyword in function parameters?

  • a) To indicate no parameters
  • b) To indicate variable parameters
  • c) To indicate any type of parameters
  • d) To indicate pointer parameters
Answer: A - void in function parameters indicates that the function takes no arguments.

14. What is the correct way to declare a constant in C?

  • a) constant int x = 5;
  • b) #define x 5
  • c) const int x = 5;
  • d) Both b and c
Answer: D - Constants can be declared using either #define or the const keyword.

15. What is the range of values for a signed char in C?

  • a) 0 to 255
  • b) -127 to 127
  • c) -128 to 127
  • d) 0 to 127
Answer: C - A signed char typically uses two's complement representation with range -128 to 127.

16. Which of these is NOT a valid variable name in C?

  • a) _var
  • b) 2var
  • c) var2
  • d) var_name
Answer: B - Variable names cannot start with a digit in C.

17. What is the purpose of the 'extern' keyword?

  • a) To declare a global variable
  • b) To extend the visibility of a variable
  • c) To make a variable constant
  • d) To allocate memory dynamically
Answer: B - 'extern' is used to declare a variable that is defined in another file or later in the same file.

18. What is the output of: printf("%d", sizeof('a'));

  • a) 1
  • b) 2
  • c) 4
  • d) Compiler dependent
Answer: C - In C, character constants are of type int, so sizeof('a') is typically 4 bytes.

19. Which loop is guaranteed to execute at least once?

  • a) for
  • b) while
  • c) do-while
  • d) All of the above
Answer: C - The do-while loop checks the condition after executing the body, so it always executes at least once.

20. What is the purpose of the 'volatile' keyword?

  • a) To optimize variable access
  • b) To prevent compiler optimization
  • c) To make a variable constant
  • d) To allocate memory in CPU registers
Answer: B - 'volatile' tells the compiler that the variable may change unexpectedly, preventing optimization.
« 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.