1

I need to create this function:

void lpLoadFileFunc(int (*loadFile)(char *filename, FILE **file))

To do this I must first create this function:

int loadFile (char *filename, FILE **file))

This function should upload a file and return if the load was successful.

But I fail to understand why using double pointer.

Can you help?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
luis
  • 23
  • 3

1 Answers1

1

C is a pass by value. When you pass a variable to a function it gets copied and a change of that copy will not change the original variable. You can however pass an address of a variable, the function will get a pointer to that variable, which enables you to change it. Don't forget that a pointer is still a variable and if you want to change a pointer you need a double pointer.

void Test( int value , int* pointer )
{
    value = 1 ;
    *pointer = 1 ;
}

int one = 0 ;
int two = 0 ;

Test( one , &two ) ;

printf( "%d %d\n" , one , two ) ;

As you can see, one did not change.

2501
  • 25,460
  • 4
  • 47
  • 87