Q. What will be the output of the following C code?

Code:
#include <stdio.h>

int main()
{
    float x = 21.0;
    x %= 3.0;
    printf("%f",x);

    return 0;
}
  • (A) 7
  • (B) 7.00
  • (C) 7.000000
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (D) Error
Explanation: In the above code, we are performing modulus operation with float values. Modulus operator doesn't work with float and double operands. Thus, the output will be:

error: invalid operands to binary % (have ‘float’ and ‘double’)
Explanation by: Kanak Sharma
In the above code, we are performing modulus operation with float values. Modulus operator doesn't work with float and double operands. Thus, the output will be:

error: invalid operands to binary % (have ‘float’ and ‘double’)

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
253
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Kanak Sharma
Publisher
πŸ“ˆ
82%
Success Rate