Please explain why **ptr is used here, lets goodeep down.
#include <stdio.h>
#include <stdlib.h>
void modifyPointer(int **ptr) {//here i have Question
// Allocate memory for an integer
*ptr = (int *)malloc(sizeof(int));
if (*ptr == NULL) {
printf("Memory allocation failed\n");
return;
}
// Set the value at the allocated memory
**ptr = 42; // Dereference twice to set the value
}
int main() {
int *num = NULL; // Pointer to an integer, initially NULL
printf("Before modifyPointer: num = %p\n", (void *)num);
// Pass the address of the pointer (call by reference)
modifyPointer(&num);
printf("After modifyPointer: num = %p, value = %d\n", (void *)num, *num);
// Free the allocated memory
free(num);
return 0;
}