实例 C 语言使用解引用运算符* 获取变量的值

x
 
#include <stdio.h>
int main() {
  int myAge = 43;  // Variable declaration
  int* ptr = &myAge;  // Pointer declaration
  // Reference: Output the memory address of myAge with the pointer (0x7ffe5367e044)
  printf("%p\n", ptr);
  // Dereference: Output the value of myAge with the pointer (43)
  printf("%d\n", *ptr);
  
  return 0;
}
                    

输出结果

0x7ffe5367e044
43