Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of this program?

#include <stdio.h>
 struct 
{
 int i;
 float ft;
}decl;
int main(){
    decl.i = 4;
 decl.ft = 7.96623;
 printf("%d %.2f", decl.i, decl.ft);
 return 0;
}

 

  • A.4 7.97
  • B.4 7.96623
  • C.Compilation error
  • D.None of the above

Answer: A

Correct answer: 4 7.97

%.2f prints the float rounded to two decimal places, so 7.96623 comes out as 7.97. The rounding is in the output only - the stored value is unchanged. The structure has no tag, but that is legal because the variable decl is declared with it.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.