未分类题

C++初学sizeof问题

char* p[]={'Robert Redford','Hopalong Cassidy','Lassle','Slin Pickens','Boris Karloff','Olicer Hardy'};
char* pstart='Your lucky star is ';
int count= (sizeof p)/(sizeof p[0]);
int dice= 0;
cout<<endl
<<'Pick a lucky star!'
<<'Enter a number between 1 and '<<cout<<':';
    cin>>dice;
cout<<endl;
if(dice>=1 && dice<=count)
cout<<pstart<<p[dice-1];
else
cout<<'Sorry,you haven't got a lucky star';
cout<<endl;
return 0;
这是从本书上看到的  我想知道第三个语句中的count是什么?应该是算数组里有多少个数据 可是这个语句算不出来吧 这可是char型而且数组中每个数据长度都不一样 我想知道这个 count的表达式怎么写是对的?

【参考答案】


(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)