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

Discussion

Predict the output of below code:

#include "stdio.h"
#include "stdlib.h"

int main(int argc, char *argv[]) { 
    char temp[20];
    gcvt(23.45,2, temp);
    printf("%s", temp);
    return 0;
}

 

  • A.Output : 0.4
  • B.Output : 24.4
  • C.Output : 25.4
  • D.Output : 23

Answer: D

Correct answer: Output : 23

gcvt(value, ndigit, buf) converts a double to a string with ndigit significant digits - not decimal places. With ndigit = 2, 23.45 rounds to two significant figures, giving 23, which is what is printed.

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

Post your comment

Please log in or register to post a comment.