指標位置

 avatar
user_6817964
c_cpp
2 years ago
587 B
1
Indexable
Never
#include <stdio.h>

void pointerInc(int *p1, int *p2) // p1 = iptr = &i; p2 = &j;
{
    printf("&p1 = %p\n", &p1);
    printf("&p2 = %p\n", &p2);
    printf("p1 = %p\n", p1);
    printf("p2 = %p\n", p2);

    *p1 += 1;
    p1 = p2;
    *p1 += 2;
}


int main()
{
    int i = 10, j = 20;
    int *iptr = &i;

    printf("&i = %p\n", &i);
    printf("&j = %p\n", &j);
    printf("&iptr = %p\n", &iptr);

    printf("i, j = %d, %d\n", i, j);
    pointerInc(iptr, &j);
    printf("i, j = %d, %d\n", i, j);
    *iptr += 5;
    printf("i, j = %d, %d\n", i, j);

}