#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
char g_file_name[100] = "this is a test";
char * g_str_ptr = "this is a test";
int main()
{
char file_name[100] = "stat_test.c";
struct stat statbuf;
int ret = stat(file_name, &statbuf);
return 0;
}
查看
(gdb) p g_file_name
$6 = 1936287860
(gdb) p (char *)g_file_name
$7 = 0x73696874 <error: Cannot access memory at address 0x73696874>
(gdb) p (char *)&g_file_name
$8 = 0x201040 <g_file_name> "this is a test"
(gdb) x/s (char *)&g_file_name
0x201040 <g_file_name>: "this is a test"
(gdb)
需要取出数组的第一元素的地址来打印,才能正常显示字符串.