根据 ftell,我的文本文件的大小是 25 个字节。但是,当我使用 ftell 作为 char 数组的大小时,sizeof 给了我 200。什么给了我?

the size of my text file is 25 bytes, according to ftell. However, when I use ftell as the size of a char array, sizeof gives me 200. what gives?

本质上,这是我的问题。

FILE *fp = "/my/textfile/location";
fseek(fp, 0L, SEEK_END);
int size = ftell(fp);

char *output_string[size];

printf("%d", size); // gives me 25
printf("%ld", sizeof(output_string)); // gives me 200.

为什么当 ftell 返回的 int 是 20 时 sizeof(output_string) 给我 200?

傻我

我不小心在我的数组声明中写了 *,这使 output_string 成为一个指针数组,而不是字符数组

char *output_string[size];

这是指针数组,如果你是运行在64位机器上, 一个指针是64位的,也就是8个字节。 如果大小为 25,则:

sizeof(output_string) = 25 * sizeof(char *) = 25 * 8 = 200