有关指针,地址和数组名等等。。

//发现的一些以前没有注意到的现象。。。。

 

#include<iostream>

using namespace std;
void ref(char* (&ch)[3])
{
 cout<<"ch:/t"<<ch<<endl;
 cout<<"&ch:/t"<<&ch<<endl;
 cout<<"&ch[0]:/t"<<&ch[0]<<endl;
}
void argu(char* ch[])
{
 cout<<"ch:/t"<<ch<<endl;
 cout<<"&ch:/t"<<&ch<<endl;
 cout<<"&ch[0]:/t"<<&ch[0]<<endl;
}
int main(int argc,char* argv[])
{
 char* ch[3];
 ch[0]="abc";
 cout<<"using reference:"<<endl;
 ref(ch);
 cout<<"using var argument:"<<endl;
 argu(ch);
 cout<<"original adress:"<<endl;
 cout<<"ch:/t"<<ch<<endl;
 cout<<"&ch:/t"<<&ch<<endl;
 cout<<"&ch[0]:/t"<<&ch[0]<<endl;
 cout<<"---------------------"<<endl;
 int v[]={1,2,3};
 int* vp=v;
 int i=0;
 int i1=1;
 int* const cicp=&i;
// cicp=&i1;//l-value specifies const object
 cout<<cicp<<endl;
 cout<<&cicp<<endl;
/* int n=1;
 int* pn=&n;
 cout<<pn<<endl;
 cout<<&pn<<endl;
 cout<<n<<endl;
 cout<<&n<<endl;

  
 cout<<"---------------------"<<endl;

 cout<<ip<<endl;
 cout<<&ip<<endl; */
 cout<<"---------------------"<<endl;
 cout<<sizeof(vp)<<endl;
 cout<<*vp<<endl;
 cout<<vp<<endl;
 cout<<&vp<<endl;
 cout<<*&vp<<endl;
// cout<<*vp<<endl;
 cout<<"---------------------"<<endl;
 cout<<sizeof(v)<<endl;
 cout<<*v<<endl;
 cout<<v<<endl;
 cout<<&v<<endl;
 cout<<*&v<<endl;
 cout<<"---------------------"<<endl;
 cout<<v[0]<<endl;
 cout<<&v[0]<<endl;
 cout<<&v[1]<<endl;
 return 0;
}

待续。。。。。。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值