#include <stdio.h>
#include <stdlib.h>
void changeAddressofPtr(int ** ptr);
int main()
{
int num = 12;
int * numptr = #//num pointer points to num variable
printf("%d\n",*numptr); //just a check
changeAddressofPtr(&numptr); //send address of pointer to be able to change it
printf("%d",*numptr); //check value after changing
return 0;
}
void changeAddressofPtr(int ** ptr)
{
int newNum = 8;
*ptr = &newNum; //make main's pointer point to newNum
}
I was trying this out and expected an error or some wrong garbage value printed in the second printf() but this is the output:
12
8 //Value of variable I thought would be deleted