Program
main ( )
{
int i;
i = 0;
printf (" The value of i before call %d \n", i);
f1 (&i); // A
printf (" The value of i after call %d \n", i);
}
void (int *k) // B
{
*k = *k + 10; // C
}
Explanation
- Statement C changes the value at the location specified by *k.
- The function is called by passing the address of i using notation &i.
- When the function is called, the address of i is copied to k, which holds the address of the integer.
- Statement C increments the value at the address specified by k.
- The value at the address of i is changed to 10. It means the value of i is changed.
- The printf statements after the function call prints the value 10, that is, the changed value of i.
No comments:
Post a Comment