I'd like to ask why is it possible to change the pointer value of file in C function without passing reference to it, what I mean is:
void fun(FILE *f)
{
fclose(f);
f = fopen("newfile", "r");
}
int main(void)
{
FILE *old = fopen("file", "r");
char *msg = (char*)malloc(sizeof(char) * 100);
fun(old);
fscanf(old, "%s", msg);
printf("%s", msg);
free(msg);
return 0;
}
Can anyone explain it to me? I was thought that pointers are being copied so I expected to get an error about closed file. Surprisingly I didn't get it.