Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

memory - How garbage values are assigned to variables in c

C code :

int a;
printf("
 %d",a); // It'll print some garbage value;

So how does these garbage values are assigned to uninitialized variables behind the curtains in C?

Does it mean C first allocates memory to variable 'a' and then what ever there is at that memory location becomes value of 'a'? or something else?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Does it mean C first allocates memory to variable 'a' and then what ever there is at that memory location becomes value of 'a'?

Exactly!

Basically, C doesn't do anything you don't tell it to. That's both its strength and its weakness.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...