小编Arn*_*old的帖子

格式化代码以访问struct类型的数组索引

我在C中有以下代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    typedef struct sample { 
        int num;        
    } abc;

    typedef struct exmp{        
        abc *n1;        
    } ccc;

    abc *foo;
    foo = (abc*)malloc(sizeof(foo));
    ccc tmp;
    tmp.n1 = foo;

    ccc stack[10];

    stack[0] = tmp;
    printf("address of tmp is %p\n",&tmp);
    // need to print address contained in stack[0]

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

在上面的代码中,我想检查地址at stack[0]是否与tmp 的地址相同.stack[0]当我打印出tmp的地址时,如何打印地址?

c pointers

0
推荐指数
1
解决办法
52
查看次数

标签 统计

c ×1

pointers ×1