rt:
但是越界的时候指针只能读,而不可以写,具体看看这个程序就一目了然了!
// e[i].cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char *a = "addf";
char h = a[60];
cout << h << endl;
a[60] = 5;
char e[5] = "adsf";
char i = e[60];
cout << i;
return 0;
}
再看看另外一种情况,就是给指针赋一个地址以后就不会出现这么个情况了
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char *a = "addf";
char h = a[60];
cout << h << endl;
//给定一个单一的地址单元
a = &h;
a[60] = 5;
//给定一个连续的但是貌似可以“越界的”地址单元
char b[3];
a = b;
a[60] = 5;
return 0;
}
上面的程序是没有问题的