list0809.cpp

来自「teach yourself C++ in 21 days 第五版」· C++ 代码 · 共 24 行

CPP
24
字号
// Listing 8.9 - Demonstrates a stray pointer
  
typedef unsigned short int USHORT;
#include <iostream>
  
int main()
{
   USHORT * pInt = new USHORT;
   *pInt = 10;
   std::cout << "*pInt: " << *pInt << std::endl;
   delete pInt;
  
   long * pLong = new long;
   *pLong = 90000;
   std::cout << "*pLong: " << *pLong << std::endl;
  
   *pInt = 20;      // uh oh, this was deleted!
  
   std::cout << "*pInt: " << *pInt  << std::endl;
   std::cout << "*pLong: " << *pLong  << std::endl;
   delete pLong;
   return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?