why FILE* fp? why not FILE fp?
hi everybody,
my question is: why do we always use FILE * and not just FILE while declaring a file pointer |
We always use FILE * because the function fopen returns a file pointer . So to collect the returned value, which is an address, we use a file pointer.
|
so, will the following work?
Code:
main() |
No, C doesn't allow that kind of lvalue. I suggest you read up on pointers. What they are and where/why they're useful.
|
In other words,
we declare a FILE *fp because when we call fopen a FILE is created in memory, so we use the *fp to reference it from our code. As you can see from fopen's declaration: FILE *fopen(const char *path, const char *mode); " FILE *fopen " means it returns a pointer to type FILE, so as I said above, we declare a FILE *fp so we can use that pointer. |
okkk, understood. thanks all for ur replies. will read up on pointers.
|
All times are GMT -5. The time now is 05:40 PM. |