Q. Which of the following % operation is invalid?
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).