#How the flip did I just print an undefined integer (C NOT C++)

30 messages ยท Page 1 of 1 (latest)

grave gulch
#

No

#

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

frosty leaf
#

int lmao doesnt have any predefined value so the output must be garbage value

grave gulch
#

I just said that

#

Lol

stray nymph
#

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))```
stone bramble
#

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++

fresh tapir
#

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

dense grotto
#

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?)

nimble ventureBOT
#

@drifting gorge has reached level 3. GG!

real topaz
#

You can do the same in C++.

#

until that new [[indeterminate]] annotation I guess. ๐Ÿ˜Ž

#

Ye

#

Cuz Iโ€™m speaking English bro what ๐Ÿ˜ญ

real topaz
#

Imagine not

grave gulch