【发布时间】:2012-11-26 15:31:12
【问题描述】:
我对@987654322@ 有一个奇怪的问题。它在屏幕上输出垃圾。我猜这与记忆有关。看看:
char string1[] = "SAMPLE STRING";
char string2[20]; // some garbage in it
/* let's clear this madness*/
int i = 0;
for (i; i < 20; i++) string2[i] = ' '; // Space, why not.
printf("output: %s", string2);
输出
output: ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠SAMPLE STRING
// ten spaces and random characters, why?
【问题讨论】:
-
你确定不是20个空格,然后是随机字符吗?
-
╠ 在代码页 437 中为 0xCC,MSVC fills 0xCC to uninitialized memory to help debugging。这意味着您访问了未初始化的内存。你可以在这里找到关于 ╠ 和 0xCC 的大量问题