内存读异常示例程序

来源:互联网 发布:usb打印机网络共享器 编辑:程序博客网 时间:2024/05/06 04:45

// 内存读异常示例程序
// VC 2008
// 编译选项: /EHa
#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
 char* pCH0 = new char;
 *pCH0 = 0;
 char* pCH = pCH0;
 long int iCount = 0;
 long int iLoopCount  = 0;
 try
 {
  while(pCH)
  {
   iLoopCount++;
   iCount += *pCH;
   pCH++;
  }
 }
 catch (...)
 { 
  printf(" Error!/n");
 }

 printf(" pCH0/t= 0x%X/n pCH/t= 0x%X/n iCount/t= %u/n iLoop/t= %u",
  pCH0,  pCH, iCount, iLoopCount);
 
 delete pCH0;

 return 0;
}

/*
执行结果(DEBUG):
Error!
pCH0   = 0x393250
pCH    = 0x395000
iCount = 252733
iLoop  = 7601
*/

原创粉丝点击