打印数组的索引下标
1. 例子
#include <stdio.h>
int num[10] = {
1 << 0,
1 << 1,
1 << 2,
1 << 3,
1 << 4,
1 << 5,
1 << 6,
1 << 7,
1 << 8,
1 << 9
};
int main (void)
{
int i;
for (i = 0; i < 10; i++)
printf ("num[%d] = %d\n", i, num[i]);
return 0;
}
在gdb中,当打印一个数组时,缺省是不打印索引下标的:
(gdb) p num
$1 = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}
如果要打印索引下标,则可以通过如下命令进行设置:
(gdb) set print array-indexes on
(gdb) p num
$2 = {[0] = 1, [1] = 2, [2] = 4, [3] = 8, [4] = 16, [5] = 32, [6] = 64, [7] = 128, [8] = 256, [9] = 512}
参考资料
1. gdb手册
2. 打印数组的索引下标https://sourceware.org/gdb/current/onlinedocs/gdb.html/Print-Settings.html#index-set-print
标签:下标,打印,索引,gdb,num,数组 From: https://www.cnblogs.com/sunbines/p/17765970.html