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

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

 

#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
    评论
指针数组、结构和函数在 C/C++ 语言中都是非常重要的概念,它们的运用是程序员必须要掌握的核心技能之一。 指针指针是 C/C++ 中非常重要的一个概念,它是内存地址的抽象,可以通过指针来访问内存中的数据。指针可以用来实现动态内存分配、函数参数传递、数据结构的实现等等。指针的运用需要注意内存安全问题,避免出现越界访问等问题。 数组数组是一种用来存储多个相同类型数据的数据结构,数组的下标从0开始。C/C++ 中的数组可以用来存储各种数据类型,包括基本数据类型、结构体等。数组可以通过下标来访问其中的元素,也可以通过指针来访问数组中的元素。 结构体:结构体是 C/C++ 中的一种自定义数据类型,它可以由多个不同类型的数据成员组成。结构体可以用来表示复杂的数据结构,比如一个人的信息、一个图形的属性等等。结构体的运用需要注意结构体成员的访问方式和结构体指针的使用。 函数:函数是 C/C++ 中的一种重要的代码模块,它可以实现特定的功能,可以分解程序的复杂性,提高程序的可维护性和可重用性。函数可以有参数和返回值,也可以通过指针来修改调用者的数据。函数的运用需要注意参数传递的方式、返回值的类型和指针的使用。 以上是指针数组、结构和函数的基本概念和运用,它们的深入理解和熟练掌握,对于程序员来说是非常重要的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值