首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

为什么*p[1] 指不到值?解决方案

2012-02-21 
为什么*p[1] 指不到值?intmain(){floatV[3]{0,10,20}float*pVVcout *V *V endlcout *(V+1

为什么*p[1] 指不到值?
int   main()
{

float   V[3]={0,10,20};
float*   pV   =   V;
  cout   < <   "*V           "       < <   *V           < <   endl;
  cout   < <   "*(V+1)   "       < <   *(V+1)   < <   endl;
  cout   < <   "   V           "       < <     V           < <   endl;
  cout   < <   "&V           "       < <   &V           < <   endl;
  cout   < <   "pV           "       < <     pV         < <   endl;
  cout   < <   "pV[0]     "       < <     pV[0]   < <   endl;
  cout   < <   "pV[1]     "       < <     pV[1]   < <   endl;
  cout   < <   endl;

float(*   p)[3]   =   &V;
  cout   < <   "   p           "       < <     p           < <   endl;
  cout   < <   "*p           "       < <   *p           < <   endl;
  cout   < <   "*p[0]     "       < <   *p[0]     < <   endl;
  cout   < <   "*p[1]     "       < <   *p[1]     < <   endl;
  cout   < <   "*p[2]     "       < <   *p[2]     < <   endl;
  cout   < <   "**(p+1)     "       < <   *(*p+1)     < <   endl;
  cout   < <   "**(p+2)     "       < <   *(*p+2)     < <   endl;
  cout   < <   "   p[0]     "       < <     p[0]     < <   endl;
  cout   < <   "   p[1]     "       < <     p[1]     < <   endl;
}

//   cout   < <   "*p[1]     "       < <   *p[1]     < <   endl;
  //cout   < <   "*p[2]     "       < <   *p[2]     < <   endl;
  指不到值.


[解决办法]
cout < < "*p[0] " < < (*p)[0] < < endl;
cout < < "*p[1] " < < (*p)[1] < < endl;
cout < < "*p[2] " < < (*p)[2] < < endl;
[解决办法]
一维数组
*(p+n) = p[n]

热点排行