首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
若有以下程序 struct stu {char*name,gender;int score;}; main(){struct stu a={NULL,’m’,290),b; a.name=(char*)malloc(10);
若有以下程序 struct stu {char*name,gender;int score;}; main(){struct stu a={NULL,’m’,290),b; a.name=(char*)malloc(10);
admin
2018-01-11
26
问题
若有以下程序
struct stu {char*name,gender;int score;};
main(){struct stu a={NULL,’m’,290),b;
a.name=(char*)malloc(10);
strcpy(a.name,"Zhao");
b=a;b.gender=’f’;b.score=350;
strcpy(b.name,"Qian");
printf("%s,%c,%d,",a.name,a.gender,a.score);
printf("%s,%c,%d\n",b.name,b.gender,b.score);}
则程序的输出结果是
选项
A、Zhao,m,290,Qian,f,350
B、Qian,f,350,Qian,f,350
C、Zhao,m,290,Zhao,e350
D、Qian,m,290,Qian,f,350
答案
D
解析
主函数中定义结构体类型struct stu,有三个成员,第一个成员为字符指针变量。主函数中为stu类型变量a赋值,阿先为a.name成员分配存储空间,存入数据。b=a;语句执行完毕以后,a和b的各个成员值相同,需要注意的是b.name和a.name成员都保存了同一段内存的地址,因此当为变量b赋值的时候,同样更改了a的name成员,而其他成员由于有单独的存储空间而不会发生改变。
转载请注明原文地址:https://kaotiyun.com/show/NLxp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
有以下程序:voidswap(char*x,char*y){chart;t=*x;*x=*y;*y=t;main(){char*s1="abc",*s2="123";swap(s1,s2);
对如下二叉树进行后序遍历的结果为()。
在结构化设计方法中,数据流图表达了问题中的数据流与加工间的关系,并且每一个__________实际上对应一个处理模块。
若有定义“floatb[15],*p=b;”,且数组b的首地址为200H,则p+13所指向的数组元素的地址为_________。
有如下程序:main(){inta=2,b=-1,c=2;if(a<0)if(b<0)c=0;elsec++;printf("%d\n",c);}该程序的输出结果是(
两个或两个以上模块之间联系的紧密程度称为()。
设有二元关系R和三元关系S,下列运算合法的是()。
假定x和y为double型,则表达式x=2,y=x+3/2的值是()。
下面关于对象概念的描述中,错误的是
下面不属于软件工程过程的4种基本活动
随机试题
改善过滤效果的关键是什么?
腹膜炎患者采用半卧位,其目的包括()。
一胎龄34周的新生儿,体温34℃,腋肛温差为正值,恢复正常体温的时间最好是( )。
城镇中发现甲类传染病和乙类传染病中的艾滋病、肺炭疽病的病人、病原携带者和疑似病人时,国家规定的报告时间是
患者,男,50岁。左下6缺失,设计双端固定桥时,对于固定连接体的要求正确的是
根据预算法律制度的规定,下列各项中,属于一般公共预算收入的有()。
英文字母A是中心对称图形.()
中国是一个农业社会,聚族而居、_______在农业大环境下,成了传统家庭的重心,由此而衍生出来的道德价值观,首先是儒家倡导的“亲亲”,形成长幼有序、孝悌仁爱的道德观念,并用家庭成员_______和继承下来的风俗习惯,有效地维护血缘秩序,履行个人在血缘等级关
①追求成熟,已经成为当今社会的一种_____________,尤其是涉世不深的年轻人,更想以老到、___________的面孔引起别人对自己的注意和重视。②事物的发展一旦停滞___________趋于保守,就将走向灭亡,___________为新生事物所取
Forsomeemployers,thepolicyoflifelongemploymentisparticularlyimportantbecauseitmeansthattheycanputmoremoneyand
最新回复
(
0
)