Reputation: 509
If you don't initialize elements in an array, you can see they are allocated a random large number when you debug. Just wondering how this number is determined?
Upvotes: 2
Views: 238
Reputation: 93964
When you declare an array, the stack pointer will be added , and then return the address of the first element. That's all, data in memory will not be changed.
Upvotes: 0
Reputation: 62469
Technically it's undefined behavior to read uninitialized variables. They can be anything, ranging from leftover memory junk to compiler predefined values.
Upvotes: 2
Reputation: 24905
These are just those values which are already present in the memory where the space for the array is allocated. So, there is no "determination" going on here.
Upvotes: 3