W3School TIY Editor

  • W3School 在线教程
  • 改变方向
  • 暗黑模式
​x
 
#include <iostream>
#include <string>
using namespace std;
​
int main() {
  string food = "Pizza";  // 变量声明
  string* ptr = &food;    // 指针声明
​
  // 引用:通过指针输出 food 的内存地址
  cout << ptr << "\n";
​
  // 解引用:通过指针输出 food 的值
  cout << *ptr << "\n";
  return 0;
}