fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int x = 10;
  7. int* ptr; // 宣告
  8. ptr = &x; // address-of operator; 取址運算子
  9.  
  10. cout << "x = " << x << endl;
  11. cout << "&x = " << &x << endl;
  12. cout << "ptr = " << ptr << endl;
  13. cout << "&ptr = " << &ptr << endl;
  14.  
  15. cout << "*ptr = " << *ptr << endl; // content-of operator;
  16. // 取值運算子
  17. *ptr = *ptr + 1;
  18. cout << "x = " << x << endl;
  19.  
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
x = 10
&x = 0x7fff819d13ac
ptr = 0x7fff819d13ac
&ptr = 0x7fff819d13b0
*ptr = 10
x = 11