I am just having one confusion that if I do not initialize the pointer and if I print its value then how come it prints some random location , how is this random location calculated and each time I run my code it remains same , whats the reason behind this ?
Where does the uninitialized pointer point ?
Collapse
X
-
Tags: None
-
What can I say? The entire computer memory consists of bits. You create a pointer and you get ownership of some of these bits. What's the value? Could be anything. Could it be from a previous run of your program? Why not?
Don't waste time trying to figure out why you get an indeterminate result.
You must absolutely initialize a pointer to a known value before you use it. -
Sir I am having just one confusion that why does this random address printed all and over again similarly , although compiler generates logical addresses but still regarding this random location , its just run time so then how is this value printed every time same only ?Comment
-
Do you know your compiler allocates memory? Unless you put an address you know in that pointer, the contents of the point are meaningless.
In other words, values you didn't place in your variables are garbage values. By any chance are you using Visual Studio? That compiler places a value in all of your pointers that it can use to tell if the pointer has not been initialized. So even though this compiler sees that value as known (since it put it there), to you, it is a garbage value.Comment
Comment