简单指针运算c语言

#include
#include

int main() {
      // 指针运算
    int i = 1;
    int *p = &i;
    printf("Value of i: %d\n", i);
    printf("Value of p: %p\n", (void*)p );
    printf("Value of p + 1: %p\n", (void*)(p + 1) );
    printf("Value of p - 1: %p\n", (void*)(p - 1) );
    printf("Value of p + 2: %p\n", (void*)(p + 2) );
    printf("Value at *(p + 1): %d\n", *(p + 1) ); // 注意这里解引用p+1

    return 0;
}
/*  Value of i: 1
Value of p: 000000000062FE14
Value of p + 1: 000000000062FE18
Value of p -1: 000000000062FE10
Value of p + 2: 000000000062FE1C
Value at *(p + 1): 6487572   */

你可能感兴趣的:(算法,数据结构,c语言,指针)