MCQ Single Best Answer Easy

QWhat is the output of the following C code?

#include <stdio.h>
int main()
 {
   float x = 'b';
   printf("%f", x);
   return 0;
 }

ID: #895 Data Types in C Language 12,937 views
Question Info
#895Q ID
EasyDifficulty
Data Types in C LanguageTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A b
  • B b.0000000
  • C run time error
  • D 98.000000
Correct Answer: Option D

Explanation

Output:

98.000000

Since the ASCII value of b is 98, the same is assigned to the float variable and printed.

This code is a C language program that includes the standard input/output library and defines the main function.

Within the main function, there is a declaration of a float variable x which is assigned the ASCII value of character 'b'.

The printf statement is then used to print the value of the x variable as a floating-point number using the %f format specifier.

Since the ASCII value of 'b' is 98, the output of the program will be 98.000000.

Finally, the main function returns an integer value of 0 to signify that the program has executed successfully.

Share This Question

Challenge a friend or share with your study group.