指针赋值的区别,请指教
//有一个问题#include <iostream.h>
struct Person
{
char name[20];
unsigned long id;
float salary;
};
Person num[6]={{"jone",12345,339},
{"david",1382,449.0},{"marit",27614,311},{"jasen",4235,623},{"peter",23876,400},{"yoke",12335,511}};
void main()
{
Person *p1[6]={&num[0],&num[1],&num[2],&num[3],&num[4],&num[5],};
//Person *p1=num;替换上一句为什么不行??????????
Person *temp;
for(int k=0;k<6;k++)
{
cout<<p1[k]->name<<endl;
}
/*
最简单的一种方式
Person temp;
for(int i=1;i<6;i++)
for(int j=0;j<6-i;j++)
{
if(p1[j]->salary>p1[j+1]->salary)
{
temp=p1[j];
p1[j]=p1[j+1];
p1[j+1]=temp;
}
}
*/
}