c - What happens to a double variable when %d is used in a printf? -
so today class teacher give 3 problems , said research @ home.. try hard solution. there no exact article it.
the code is:
#include <stdio.h> int main(void){ double x = 2.3; printf("%d\n", x); printf("%d, x\n"); printf("%d\n", "x"); }
the output is:
- 1717986918
- 1717986918, x
- 4206639
i know need use %lf double. want know problem when used %d. think there memory problem ( 4bit 8bit) or garbage. want know more details problem. assignment. tia
what happens double variable when %d used in printf?
undefined behavior. you're not supposed misuse format specifiers printf.
so working fine program crash sigsegv possibility.
what happen tries treat double
int
, , depending on how os saves these, garbage print.
Comments
Post a Comment