#How the flip did I just print an undefined integer (C NOT C++)
30 messages ยท Page 1 of 1 (latest)
When u have an uninitialized variable it gets like a garbage value assigned
It's whatever is at the memory at that location but it's not the address
int lmao doesnt have any predefined value so the output must be garbage value
take the time of your pc in days (include hour, min and sec)
convert to ms
thats the value
- windows's random number gen is not random
just print rand() with srand as time(NULL)
include cstdlib
you can also
srand(reinterpret_cast<unsigned int>(time(NULL))```
It's undefined behavior because the variable is uninitialized
What happens depends on the compiler because there is no specific rule for this case in C++
g++ for example uses time
its a "known bug"/ "security issue" everyone accepted because it is C, also its a super ez fix when using it. so as the classic C saying goes "just dont f*ck up", also this bs still happens to me wayy to often
it's undefined behaviour to try to read the value of an unitialized variable in C
don't make any assumptions about might happen, your compiler is allowed to produce whatever code it wants when you evoke undefined behaviour
in practice, what will happen is that you will be reading the value that is currently in memory at that point (perhaps remnants of a previous process?)
@drifting gorge has reached level 3. GG!
You can do the same in C++.
until that new [[indeterminate]] annotation I guess. ๐
Ye
Cuz Iโm speaking English bro what ๐ญ
Actually you can still do the same stuff but you just need to write more.

Imagine not
random.org only real