C++ Struct

//指出下面程序的问题
/*typedef struct TagStu
{
  int n;
}Stu;
void test(Stu* s[])
{
  cout<<s->n<<endl;
  cout<<(++s)->narrow<<endl;
}
int main()
{
  Stu* sTmp;
  sTmp = new Stu[10];
  test(sTmp); //传递的实参为指针,而test函数形参为Stu指针类型的数组,
  delete [] sTmp;
  return 0;
}*/

//修改为
typedef struct TagStu
{
  int n;
}Stu;
void test(Stu* s,int len)
{
  cout<<s->n<<endl;
  cout<<(++s)->n<<endl;
}
int main()
{
  Stu* sTmp;
  sTmp = new Stu[10];
  test(sTmp,10);
  delete [] sTmp;
  return 0;
}

原文地址:https://www.cnblogs.com/fenghuan/p/4885270.html