構造体でよくわからないところが出たので質問させてもらいます;;
次のプログラムがあったのですが、6行目のところで
struct Goods *foo(struct Goods gs[/url]){
とありますが、この「*」はなぜつけるのでしょうか?
struct Goods{
char name[30];
int price;
};
struct Goods *foo(struct Goods gs[/url]){
int max = 0;
int idx = 0;
int i;
for(i=0;i<5;i++){
if(max < gs.price){
max = gs.price;
idx = i;
}
}
return &gs[idx];
}
int main(void){
struct Goods *pg;
struct Goods gs[5] = {
{"鉛筆",30},
{"消しゴム",50},
{"ノート",100},
{"ボールペン",80},
{"クリップ",20}
};
pg = foo(gs);
printf("もっとも値段の高い商品は\n");
printf("%s(%d円)\n",pg->name,pg->price);
printf("です\n");
return 0;
}