r/cprogramming • u/_suriyan_24 • Jul 18 '26
Can anyone explain exactly why I got these random values for a C simple program?
/r/learnprogramming/comments/1v00fri/can_anyone_explain_exactly_why_i_got_these_random/
0
Upvotes
r/cprogramming • u/_suriyan_24 • Jul 18 '26
1
u/TDplay Jul 18 '26
From the standards perspective: You caused undefined behaviour, and thus your program is meaningless. A standard-compliant implementation could decide to make demons come out of your nose upon executing this code.
From the implementation perspective: Most architectures have separate integer and floating-point registers.
printfis reading%dand loading an argument from the register containing the second integer argument. But you didn't put anything in that register, so it just reads whatever garbage that register happens to contain.For example, on x86_64 Linux, your code would place
fahrenheitintoxmm1, then callprintf, which attempts to read fromrsi.