gpt4 book ai didi

c - C 中的 FILE 指针如何工作?

转载 作者:太空狗 更新时间:2023-10-29 15:50:36 26 4
gpt4 key购买 nike

如果我们写:

//in main

FILE *p = fopen("filename", "anymode");

我的问题是:p 指向什么?

最佳答案

文件指针 p 指向由 C 库处理的结构,该结构在给定的打开模式下管理命名文件的 I/O 功能。

你无法先验地判断它指向的是静态分配的内存还是动态分配的内存;你不需要知道。您将其视为不透明指针。

注意标准说:

ISO/IEC 9899:2011 7.21.3 Files

The address of the FILE object used to control a stream may be significant; a copy of a FILE object need not serve in place of the original.

这(粗略地)说:不要乱动指针;将它传递给需要它的函数,否则就不要管它。

关于c - C 中的 FILE 指针如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22186626/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com