-858993460 why?

Hi there,

Can anyone tell me why variables can have printed values of -858993460.

I've got a pointer pointing to a memory address which has nothing in it so when i come to cout this it prints -858993460, if i give it a value then its prints that value. I had presumed this is "garbage" (whatever is in that chunk of memory) but another empty variable at a different memory location can have the same value.

Is it the size in bits of memory created for an int?
Is it a microsoft-ism thats supposed to tell that that block of memory is empty?

Many Thanks

Alex
Memory cannot have "nothing" in it. Memory locations are 8 bits. Each bit can have the value 0 or 1.
What you are seeing is the bit pattern that happened to be there.
So essentially its garbage, stuff left over from previous “ doings”. Below it the code that produces the empty variable:

[code]
int buff; //buff is empty, if assigned a val, that is the printed
int * ted = &buff; //assigning the pointer a momory locationint
alex = *ted; //telling the pointer to go off and find the memory address and return whatevers in it and assign it to alex

if (alex == -858993460){ cout<<"Memory location " <<&buff<<" holds "<<"NOTHING"<<N;}else { cout<<"Memory location " <<&buff<<" holds "<<alex<<N; }
[code]

The problem is when I create another variable, say int buff2, and do the same thing as above it also comes back with a printed value of -858993460, so how can two memory “chunks” hold the same garbage?

Please feel free to let me know if i'm barking up the wrong tree here as i'm farly new to c++.

Thanks

Alex
What compiler are you using? It may be it doesn't assign a unique address to uninitialised variables, so you're getting the same location for both? Or it may be it automatically initialises them to that number for some reason (though can't imagine why, it's not a power of 2).

Do they consistently get that value in multiple compilations/running of the program?
-858993460 == 0xcccccccc in hex.

This bit pattern is often used by microsoft compilers to detect buffer overruns and such.
Topic archived. No new replies allowed.