Home / Programming MCQs / C Programming MCQs / Question

K

Kanak Sharma • 5.38K Points
Tutor III

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

Code:
#include <stdio.h>

int main()
{
    float x = 23.456;
    printf("%.2f",x);
    return 0;
}
(A) 23.45600
(B) 23.456
(C) 23.45
(D) 23.46
Explanation by: Kanak Sharma
In the above code, the value of x is 23.456 and we are printing the value of x using the %.2f format specifier. %.2f rounds the value and prints the 2 digits after the decimal point.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.