[英]How to see the element of particular index of 2D array in gdb?
char *str = "Coding";
char arr[5][10];
for (i = 0;i< 5; i++)
{
for (j = 0; j< 10; j++)
{
if (i>=2 && j==0)
{
arr[i][j]= first_string[i-2];
}
}
}
Now I want to see the element at arr[2][3]
.现在我想查看
arr[2][3]
的元素。
When I do p arr[2][3]
, it gives当我做
p arr[2][3]
时,它给出了
Cannot perform pointer math on incomplete types, try casting to a known type, or void *.
无法对不完整类型执行指针数学运算,尝试强制转换为已知类型或 void *。
Add a line to your program after the for
loops在
for
循环之后向程序添加一行
int main(void)
{
...
return 0; // Line 20
}
Compile with -g
(debug mode on)使用
-g
编译(开启调试模式)
gcc -std=c11 -Wall -g -o demo demo.c
Launch your program with gdb使用 gdb 启动您的程序
gdb demo
set a breakpoint at line 20 (the line coresponding to return 0;
)在第 20 行设置断点(对应于
return 0;
的行)
break 20
run the program运行程序
run
print the value of the array打印数组的值
print arr[2][3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.