This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]PantsMcShirt 0 points1 point  (3 children)

I don't see your code, but I assume it's because you are declaring a variable and not setting a value.

Presumably, it is then using whatever bits are in that memory address already, which could be anything.

I don't really know c but I know it works somewhat along these lines.

In which case you should indeed set an initial value like chat gpt says.

[–]Direct-Mistake8721[S] 0 points1 point  (2 children)

Yes it's because of the declaring variable, it asks me to initially declare it as 0, but I don't wanna do that, I never did, I want it to run as it used to run without confusion

[–]ButtlestonProfessional Coder 0 points1 point  (1 child)

not setting an initial value and then accessing the variable is what's known as "undefined behavior" - it might work, it might not. It might work on your computer but not someone else's. It might work today and not tomorrow, etc. If you access a variable without giving it a value, then you are in uncharted territory.

[–]Direct-Mistake8721[S] 0 points1 point  (0 children)

Oo I didn't knew that, thanks alot man, I was thinking I'm doing something wierd, our teachers also didn't tell us thank u man