简体   繁体   English

如何跟踪这个堆栈和指针

[英]how to trace this stack and pointer

#include<stdio.h>
#include<stdlib.h>
struct test
{
    int *p;
};
typedef struct test * TESTP;
struct ex
{
TESTP *testpp;
};
typedef struct ex * EXP;
void main(void)
{
    int x=10;
    struct test t2; 
    TESTP t1=(struct test *)malloc(sizeof(struct test));
    EXP e1=(EXP)malloc(sizeof(struct ex));
    (e1->testpp)=&t1;
    t1->p=&x;
    printf("%d\n",**(e1->testpp));
}

I would like to trace back to value stored at pointer p(ie, 10), by using e1. 我想通过使用e1追溯到存储在指针p(即10)的值。 is that possible to trace that? 有可能追踪到那个吗? This code edited accidentally, i am not sure this will work. 这段代码意外编辑,我不确定这是否有效。 if it works please show me how can i trace back to value in 'p' using 'e1'. 如果它有效,请告诉我如何使用'e1'追溯'p'中的值。

You want to be able to dereference a chain starting with e1 getting to p eventually. 您希望能够取消引用从e1开始到p的链。

Here is how you do that: 这是你如何做到这一点:

printf("%d\n",*((*(e1->testpp))->p));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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