+ 2
i address is same two times..
And k address is same in both statements..
You mean i, k are same variables? No those are two different variables..
i is local variable to main function and its not exist or available to test function.
And same way, k is a local variable declared in test function. And exist only in test function.
from main i value is passed to function through as parameter and its value is copied in variable k. Two are different variables in memory..
Hope it helps...
+ 3
I think this comes from the fact that you are printing the address of `k` instead of its value which is the address of `i` ... and other fixes:
// just be careful using addresses and pointers
#include <stdio.h>
void test(int *k);
int main() {
int i = 0;
printf("The address of i is %p\n", &i);
test(&i);
printf("The address of i is %p\n", &i);
test(&i);
return 0;
}
void test(int *k) {
printf("The address of k is %p\n", k);
return;
}
0
You're welcome vipul jain