C语言趣事之内存泄露

C语言定义变量,分配内存时采用的是栈模式,于是乎,就有了如此如此,这般这般的效果

#include<iostream>
using namespace std;

int main()
{
	int a = 66666;
	int b = 22222;
	int c[2] = {333333,44444};
	
	cout << " 修改前的值 " << endl;
	
	cout << " c[2]= " << c[2] << endl;
	
	cout << " c[3]= " << c[3] << endl;
	
	c[3] = 12345; //修改c[3]的值
	
 	cout << "修改后的值:" <<endl;

	cout << " c[3]= "<< c[3] << endl;
	
	cout << "  a= "<< a << endl;
	 
	return 0;
} 

  同理,我们可以利用指针这种东西,如下

#include<iostream>
using namespace std;

int main()
{
	int a = 0;
	int *p = &a;
	
	for(int i=0;i<10;i++)
	{
		cout << p << " : ";
		cout << *p++ << endl;
	}
	
	return 0;
}

  想到没有?知不知道一种叫做XX游侠的作弊器?笑.....

posted on 2011-12-14 19:15  悲笑菩提  阅读(495)  评论(0)    收藏  举报

导航