#include <iostream>
int main()
{
using namespace std;
double wages[3]={10000.0,20000.0,30000.0};
short stacks[3]={3,2,1};
//取得内存地址
double * pw=wages;//double * pw= &wages[0];与这种写法是相同的
short * ps=&stacks[0];
cout<<"pw= "<<pw<<",*pw= "<<*pw<<endl;
pw=pw+1;
cout<<"Add 1 to the pw pionter:\n";
cout<<"pw= "<<pw<<",*pw= "<<*pw<<endl;
cout<<"ps= "<<ps<<",*ps= "<<*ps<<endl;
ps=ps+1;
cout<<"Add 1 to the ps pionter:\n";
cout<<"ps= "<<ps<<",*ps= "<<*ps<<endl;
cout<<"access two elements with array notation\n";
cout<<"stacks[0]="<<stacks[0]<<",stacks[1]="<<stacks[1]<<endl;
cout<<"access two elements with array notation\n";
cout<<"*stacks="<<*stacks<<",*(stacks+1)="<<*(stacks+1)<<endl;
cout<<sizeof(wages)<<"= size of wages array\n";//数组实际长度
cout<<sizeof(pw)<<"=size of pw pointer \n";//地址长度
return 0;
}
指针学习(二)指针与数组
最新推荐文章于 2023-08-12 20:58:15 发布