欢迎来到天天文库
浏览记录
ID:12035156
大小:41.00 KB
页数:8页
时间:2018-07-15
《c++一维数组和指针的关系总结》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、C++一维数组和指针的关系总结对于数组inta[10]; a表示数组的第一个元素的地址,即&a[0]; 如果使指针p,指向数组的首元素,可以进行操作: int*p=a; 或者 int*p=&a[0]; 那么p++,是指向数组中的先一个元素,即a[1]; 此时*p则是a[1]中所放的值。 此时,a[i]=p[i]=*(a+i)=*(p+i) 下面举一个例子; 直接用a[i]来输出 #include usingnamespacestd; intmain(){ inta[10]={1,2,3,
2、4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"<3、0;i<10;i++) cout< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"<4、clude usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"< usingnamespacestd; intmain(){ inta[10]={5、1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"<6、; inti=0; int*p=a; for(i=0;i<10;i++) cout<<*(p+i)<<""; cout< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10i7、ntergers:"< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"<8、p++<<"t"; } cout< usingnamespacestd; intmain(){ inta[10]={1,
3、0;i<10;i++) cout< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"<4、clude usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"< usingnamespacestd; intmain(){ inta[10]={5、1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"<6、; inti=0; int*p=a; for(i=0;i<10;i++) cout<<*(p+i)<<""; cout< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10i7、ntergers:"< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"<8、p++<<"t"; } cout< usingnamespacestd; intmain(){ inta[10]={1,
4、clude usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"< usingnamespacestd; intmain(){ inta[10]={
5、1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"<6、; inti=0; int*p=a; for(i=0;i<10;i++) cout<<*(p+i)<<""; cout< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10i7、ntergers:"< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"<8、p++<<"t"; } cout< usingnamespacestd; intmain(){ inta[10]={1,
6、; inti=0; int*p=a; for(i=0;i<10;i++) cout<<*(p+i)<<""; cout< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10i
7、ntergers:"< usingnamespacestd; intmain(){ inta[10]={1,2,3,4,5,6,7,8,9,10}; cout<<"Pleaseinput10intergers:"<8、p++<<"t"; } cout< usingnamespacestd; intmain(){ inta[10]={1,
8、p++<<"t"; } cout< usingnamespacestd; intmain(){ inta[10]={1,
此文档下载收益归作者所有