matlab 中结构体的元素中有数组,那么结构体的数组中的元素如何输出?

如题所述

【答案】:#include'stdio.h'
#include'bios.h'
#include'stdlib.h'
struct s
{
char name;
int price;
}list={{'abc',4},
{'def',3},
{'ghi',4}};
main()
{
char name;
int amount,i=0, price,key,j;
for(i=0;;i++)
{
printf('input the ESC to quit,or enter any other key\n');
fflush(stdin);
key=bioskey(0)&0xff;
if((key&27)==27)
break;
else
{
printf('please input the No.%d goods' price and amount\n',i+1);
scanf('%d%d',list.name,amount);
for(j=0;strcmp(name,list.name)!=0;j++)
price=list.price*amount;
printf('%s*%d=%d',list.name,amount,list.price);
}
}
}
因为C和D中的运算符优先级是这样的:C中最高的是成员访问符然后才是括号然后是前自增然后是解引用,编译器应该是把括号认为是最高优先级的了,括号内算完后再算外边的,因为如果严格按照优先级的话最先的应该是.可是在括号没运算出来前.是无效的,所以说C编译的结果理论上不准确吧,D就很中规中矩的答案了。
个人感觉题目有问题的可能大一点,毕竟如果说学C++的理论无法用于实践学着也没用哈,所以实践更重要一些。
如果强要说只有D是对的话只有那一个解释了
参考书上是找到优先级的地方
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜