2power10
2power10

Reputation: 1279

C++ Memory allocation issue

My code is like below:

#include <string.h>
int main()
{
    int ii = 123;
    char str[7] = "";
    strcpy(str,"123456");
    return 0;
}

I run this in VS2010, the memory is like below

enter image description here

I am curious what the cc in the memory used for? And how the number of cc is calculated?

Upvotes: 5

Views: 289

Answers (2)

CodingCat
CodingCat

Reputation: 80

When you access the uninitialised memory space, VC2010 will always warn you that you have accessed some address containing 0xcccccccc,

0xcc is the value used by the compiler (in a debug build) to fill up the uninitialized memory.

Upvotes: 1

Mysticial
Mysticial

Reputation: 471199

When compile for "Debug" in Visual Studio, the cc's are often used to fill up uninitialized memory. That way it's more obvious when you access uninitialized memory.

For example, if you try to dereference an uninitialized pointer, you'll likely get something like:

Access Violation accessing 0xcccccccc

or something like that.

enter image description here

Upvotes: 7

Related Questions