Q. Which keyword is used to prevent modification of a variable?

  • (A) readonly
  • (B) final
  • (C) const
  • (D) static
πŸ’¬ Discuss
βœ… Correct Answer: (C) const
Explanation: const variables cannot be changed after initialization.

Q. What is the output of the following code?

Code:
int i = 0;
while (i < 3)
{
  printf("%d", i);
  i++;
}
  • (A) 012
  • (B) 123
  • (C) 321
  • (D) Undefined
πŸ’¬ Discuss
βœ… Correct Answer: (A) 012
Explanation: i starts from 0 and increments till less than 3.

Q. What is the value of i after this loop?

Code:
int i;
for(i = 0; i < 5; i++){}
  • (A) 4
  • (B) 5
  • (C) 6
  • (D) 0
πŸ’¬ Discuss
βœ… Correct Answer: (B) 5
Explanation: The loop increments i after the last check, ending with i = 5.

Q. Which function converts a string to an integer in C?

  • (A) itoa()
  • (B) stoi()
  • (C) atoi()
  • (D) int()
πŸ’¬ Discuss
βœ… Correct Answer: (C) atoi()
Explanation: atoi() converts ASCII strings to integer values.

Q. Which format specifier is used to print a float?

  • (A) %c
  • (B) %d
  • (C) %s
  • (D) %f
πŸ’¬ Discuss
βœ… Correct Answer: (D) %f
Explanation: %f is used to print floating-point numbers.

Q. What is the output?

Code:
int x = 2 * 3 + 4;
printf("%d", x);
  • (A) 10
  • (B) 14
  • (C) 6
  • (D) 7
πŸ’¬ Discuss
βœ… Correct Answer: (A) 10
Explanation: Multiplication has higher precedence: 2*3 + 4 = 6 + 4 = 10.