下列程序中函数fun的功能是:统计person所指结构体数组中所有性别(sex)为M的记录的个数,存入变量n中,并作为函数值返回。请填空。 #include <stdio.h> #define N 3 typedef st

admin2009-08-24  26

问题 下列程序中函数fun的功能是:统计person所指结构体数组中所有性别(sex)为M的记录的个数,存入变量n中,并作为函数值返回。请填空。
   #include   <stdio.h>
   #define    N   3
   typedef  struct
   {  int   num;  char  nam[10];  char  sex;}  SS;
   int  fun(SS  person[])
   {  int i,n=0;
      for(i=0; i<N; i++)
      if(【  】==’M’) n++;
   return  n;
   }
   main()
   { SS W[N]={{1,"AA",’F’},{2,"BB",’M’},{3,"CC",’M’}};   int n;
       n=fun(W);  printf("n=%d\n", n);
   }

选项

答案person[i].sex

解析 本题考查的是对结构体成员的引用,对结构体数组成员的访问是以数组元素为结构体变量的,其形式为结构体数组元素咸员名,所以题目空白处应填person.sex。
转载请注明原文地址:https://jikaoti.com/ti/ZbI0FFFM
0

最新回复(0)