相关疑难解决方法(0)

在C中打印指针

我试图用指针理解一些东西,所以我写了这段代码:

#include <stdio.h>

int main(void)
{
    char s[] = "asd";
    char **p = &s;

    printf("The value of s is: %p\n", s);
    printf("The direction of s is: %p\n", &s);

    printf("The value of p is: %p\n", p);
    printf("The direction of p is: %p\n", &p);

    printf("The direction of s[0] is: %p\n", &s[0]);
    printf("The direction of s[1] is: %p\n", &s[1]);
    printf("The direction of s[2] is: %p\n", &s[2]);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

用gcc编译时我得到以下警告:

$ gcc main.c -o main-bin -ansi -pedantic -Wall -lm
main.c: In function ‘main’: …
Run Code Online (Sandbox Code Playgroud)

c pointers

41
推荐指数
3
解决办法
15万
查看次数

标签 统计

c ×1

pointers ×1