小编Pol*_*s.A的帖子

通过*指针分配后,相邻的内存空间将填充为零。为什么?

我正在阅读一本旧书“ The C Programming Language”来学习C,并且目前正在尝试使用指针。

#include <stdio.h>
int
main (void)
{
    // init string
    char s[8] = "ZZZZZZZ";
    // it goes: Z Z Z Z Z Z Z \0

    long *p;         // make pointer refering to the same adress as s
    p = s;           // but declared long for modifying 4 bytes at once
    *p = 0x41414141; // and assign hexadecimal constant equal to 65 65 65 65

    // expect output to be: AAAAZZZ
    printf ("%s\n", s);
    // but get …
Run Code Online (Sandbox Code Playgroud)

c

2
推荐指数
1
解决办法
74
查看次数

标签 统计

c ×1