main() {char a[8]={1,2,3,4,5,6,7,8}; short *p=(short*)(&a+1); cout

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 11:40:38
main(){chara[8]={1,2,3,4,5,6,7,8};short*p=(short*)(&a+1);coutmain(){chara[8]={1,2,3,4,5,6,7,8};short

main() {char a[8]={1,2,3,4,5,6,7,8}; short *p=(short*)(&a+1); cout
main() {char a[8]={1,2,3,4,5,6,7,8}; short *p=(short*)(&a+1); cout

main() {char a[8]={1,2,3,4,5,6,7,8}; short *p=(short*)(&a+1); cout
char a[8]={1,2,3,4,5,6,7,8};
short *p=(short*)(&a+1); //&a+1的含义是在a的地址上偏移1个a的长度,也就是8个char的长度,就是&a[8],然后把这个已经越界的地址强制转换成一个short*赋值给p(对一个数组名取地址按道理说是非法的,早期的c编译器是不允许这么做的,但是现在的编译器把这样的操作定义为值与该数组首地址相同,但类型是一个指向数组的地址,就是说&a相当于一个二维数组的地址了)
cout