---
title: "数组下标为-1不会crash"
author: "tinggo"
date: "2011-03-14T22:18:08Z"
tags: []
categories: ["编程语言"]
slug: "1-crash"
draft: false
lastmod: "2011-03-14T22:19:12Z"
id: 962208
url: "https://tinggo.iteye.com/blog/962208"
---

发现在栈上的指针可以随意乱动，这就会导致出现“写坏内存”的情况。今天大开眼界。

```C++

#include <iostream>
using namespace std;

struct TestClass
{
	int* pointer;
};

int main()
{
	TestClass* a =new TestClass();
	a->pointer = new int[10];
	std::cout<<a->pointer[-1]<<endl;
	return 0;
}

```