简体   繁体   中英

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

在此输入图像描述

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

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.

在此输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM