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

问题描述 投票:0回答:2

本质上,这是我的问题。

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?

c arrays file io sizeof
2个回答
0
投票

对不起我。

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


0
投票
char *output_string[size];

这是指针数组,如果您在64位计算机上运行,一个指针是64位,即8个字节。如果大小为25,则:

sizeof(output_string) = 25 * sizeof(char *) = 25 * 8 = 200
© www.soinside.com 2019 - 2024. All rights reserved.