淘宝09笔试题C++相关

来源:互联网 发布:淘宝达人怎么分享宝贝 编辑:程序博客网 时间:2024/04/27 01:01

 

 int a[3][2]={1,2,3,4,5,6},*p[3];
 p[0]=a[1];
求输出结果:
 cout<<*(p[0]+1)<<endl;//4
容易犯错的地方,误把p[0]看成指向一维数组的指针
扩展思考:
 cout<<**(&a[1]+1)<<endl;//5
 cout<<**(a+2)<<endl;//5

进一步思考:
举例,以下等价的表达:
 int a[5][3]={11,28,-5,45,90,35,23,19,0,0,34,56,-35,24,-40};
 cout<<a[4][1]<<endl;;//24
 cout<<*(*(&a[0]+4)+1)<<endl;//24
 cout<<*(*(a+4)+1)<<endl;//24
 cout<<*((a[0]+4*3)+1)<<endl;//24
 cout<<*((a+4*3)+1)<<endl;//错误!高质量C++编程第二版129页居然犯了这个错误!

 

原创粉丝点击