C代码如下:
#include<stdio.h>
int main()
{
int a[]={0,1,2,3,4};
int*p[]={a,a+1,a+2,a+3,a+4};
int**ptr=p;
ptr++;
printf("%d , %d ",*ptr-a , **ptr);
*ptr++;
printf("\n%d , %d ",*ptr-a , **ptr);
*++ptr;
printf("\n%d , %d ",*ptr-a , **ptr);
++*ptr;
printf("\n%d , %d ", *ptr-a , **ptr);
return 0;
}
我无法理解代码中的错误以及应该修改的内容。
最佳答案
你还没有在 gdb 中执行第 8 行。
8 int **ptr = p;
所以到目前为止 ptr
还没有在你的程序中定义。因此,无法访问它。您可以在 gdb 提示符下按 n
命令,然后按 print
(gdb) n
(gdb) print *ptr
此外,您的程序应该在 printf
中使用 %ld
而不是 %d
作为格式说明符,以消除编译器警告,如
printf("%ld , %ld ",*ptr-a , **ptr);
关于c - 在指针上调试 C 程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45436518/