21.9k views
2 votes
If I have int *p and function f(), such that f(&p);, then what would the prototype of f be?

User Taruxtin
by
7.4k points

1 Answer

7 votes

Final answer:

The prototype of function f() would be void f(int **ptr). When a double pointer to an integer is passed to the function, it allows for the modification of the original pointer variable or assignment of a new memory address.

Step-by-step explanation:

The prototype of function f() would be void f(int **ptr). This means that the function f() takes a double pointer to an integer as its argument.

In C, a pointer is a variable that stores the memory address of another variable. In this case, the int *p is a pointer to an integer, and &p is the address of that pointer. Passing &p to f() means that the function will receive a pointer to a pointer to an integer.

By receiving a double pointer as an argument, function f() can modify the value of the original pointer *p or even assign a new memory address to it if needed. This can be useful when you want to change the value of a pointer variable within a function.

User Joshhendo
by
8.1k points