首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
以下程序拟读取一个姓氏,查找其对应的年龄并输出: #include<stdio.h> #include<string.h> #include<stdlib.h> struct person{char name[10];int age;}; struet p
以下程序拟读取一个姓氏,查找其对应的年龄并输出: #include<stdio.h> #include<string.h> #include<stdlib.h> struct person{char name[10];int age;}; struet p
admin
2021-07-09
20
问题
以下程序拟读取一个姓氏,查找其对应的年龄并输出:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct person{char name[10];int age;};
struet person group[6]={"zhang",18,
"wang",20,
"li",19,
"zhao",18,
"liu".19
},*p;
main()
{int i,flag=0;
p=(struet person*)malloc(sizeof(struet person));
gets(&p->name);
for(i=0;i<6;i++)
if((stremp(p->name,group
.name)==0))
{printf("%d\n",group
.age);
flag=1;
}
if(flag==0)printf("No find!\n");
}
程序有语法错误,出错的是( )。
选项
A、gets(&p->name);
B、p=(struet person*)malloc(sizeof(struet person))
C、if((stremp(p->name,group
.name)==0))
D、printf("%d\n",group
.age)
答案
A
解析
语句gets(&p->name)中,gets的参数应该是成员变量name数组的首地址,而&p->name是首先获取数组name的首地址,然后再对首地址取地址符,所以这是错误的,正确参数应该是:gets(p->name);,故答案选A。
转载请注明原文地址:https://kaotiyun.com/show/j4tp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
若有以下程序段:structst{intn;int*m;};inta=2,b=3,c=5;structsts[31=({101,&a},{102,&c},{103,&b});main
设有定义:chars[10];inti=0;,以下不能将一行(不超过100个字符)带有空格的字符串正确读入的语句或语句组是()。
有以下计算公式若程序前面已在命令行中包含math.h文件,不能够正确计算上述公式的程序段是
给定程序中,函数fun的功能是将带头结点的单向链表逆置,即若原链表中从头至尾结点数据域依次为2、4、6、8、10,逆置后,从头至尾结点数据域依次为10、8、6、4、2。请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。注意:部分源程
以下是正确C语言标识符的是()。
下面结构体的定义语句中,错误的是()。
以下选项中合法的实型常量是()。
下列选项中,能够满足“只要字符串s1等于字符串s2,则执行ST”要求的是
数据库管理系统是()。
下列对队列的描述中正确的是
随机试题
深静脉血栓形成(下肢的DVT)的患者,约半数以上无自觉症状和明显体征,此时依据双侧下肢周径的测量结果来评价,双侧相差多少即可考虑有临床意义
我国水利面临的新形势是()。
填方土料应符合设计要求,一般不能选用的有()。
出境货物最迟于报关或装运前7天报检。( )
态度的结构包括认知成分、_________和行为成分。
Tom’smothertriedhardtopersuadehimto______fromhisintentiontoinvesthissavingsinstockmarket.
Accordingtotheauthor,the"SpaceRace"was______.Theauthorbringsupthetopicoftheinternationalspacestationinorder
某货车运输公司有一个中央仓库和n个运输目的地,每天要从中央仓库将货物运输到所有运输目的地,到达每个运输目的地一次且仅一次,最后回到中央仓库。在两个地点i和i之间运输货物存在费用Cij,为求解旅行费用总和最小的运输路径,设计如下算法:首先选择离中央仓库最近的
关于QoS协议特点的描述中,错误的是()。
It’sacharacter______inhimthathecan’teveracceptthathe’sinthewrong.
最新回复
(
0
)