Q. Which of the following % operation is invalid?

  • (A) 2 % 4f;
  • (B) 2 % 4l;
  • (C) Both 2 % 4f; and 2 % 4l;
  • (D) 2 % 4;
πŸ’¬ Discuss
βœ… Correct Answer: (C) Both 2 % 4f; and 2 % 4l;
Explanation:

The modulus operator % in C only works with integers (int, long, etc.). It does not support floating-point types like float or double.

Why are (A) and (B) invalid?

(A) 2 % 4f; ❌

  • 4f is a float value (4.0), and % cannot be used with float.
  • This causes a compilation error.

(B) 2 % 4l; ❌

  • 4l is a long integer, and 2 is also an integer.
  • However, % supports long, so this is actually valid.

(C) Both 2 % 4f; and 2 % 4l; ❌

  • Since 2 % 4l; is valid, this option is partially incorrect.
  • But if 4l was mistakenly assumed as long double, then it would be invalid.

(D) 2 % 4; βœ… (Valid)

  • Both 2 and 4 are integers, so % works fine.

Final Answer:

βœ… (C) Both 2 % 4f; and 2 % 4l; (assuming 4l is mistakenly considered as long double).

Explanation by: Mr. Dubey

The modulus operator % in C only works with integers (int, long, etc.). It does not support floating-point types like float or double.

Why are (A) and (B) invalid?

(A) 2 % 4f; ❌

  • 4f is a float value (4.0), and % cannot be used with float.
  • This causes a compilation error.

(B) 2 % 4l; ❌

  • 4l is a long integer, and 2 is also an integer.
  • However, % supports long, so this is actually valid.

(C) Both 2 % 4f; and 2 % 4l; ❌

  • Since 2 % 4l; is valid, this option is partially incorrect.
  • But if 4l was mistakenly assumed as long double, then it would be invalid.

(D) 2 % 4; βœ… (Valid)

  • Both 2 and 4 are integers, so % works fine.

Final Answer:

βœ… (C) Both 2 % 4f; and 2 % 4l; (assuming 4l is mistakenly considered as long double).

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
237
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Akash Lawaniya
Publisher
πŸ“ˆ
98%
Success Rate