首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
若有以下程序 #include #include #include struct stu { char *name, gender; int score; }; main() { struct stu a={NULL, ’m’, 290}, b
若有以下程序 #include #include #include struct stu { char *name, gender; int score; }; main() { struct stu a={NULL, ’m’, 290}, b
admin
2015-07-28
51
问题
若有以下程序
#include
#include
#include
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、Qian,m,290,Qian,f,350
B、Zhao,m,290,Qian,f,350
C、Qian,f,350,Qian,f,350
D、Zhao,m,290,Zhao,f,350
答案
A
解析
语句"a.name=(char *)malloc(10); strcpy(a.name, "Zhao");"将字符串"Zhao"赋值给了a中的字符指针a.name,之后把结构体a中的数据赋值给b,然后改变b的gender、score这两个成员的值,而b.name和a.name指向同一块内存地址,所以当执行语句"strcpy(b.name, "Qian");"时,b.name和a.name的值均为"Qian",所以最终结构体变量a的数据为{"Qian",?m?,290},b中的数据为{"Qian",?f?,350}。
转载请注明原文地址:https://www.kaotiyun.com/show/xKJp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
以下程序运行后,输出结果是______。 #define P4.5 #define S(x)P*x*x #include<stdio.h> main() { int a=2,b=3; printf("%.1f\n",S(a+b)); }
以下程序的输出结果是______。main(){char*s="12134211”;intv[4]={0,0,0,0},k,i;for(k=0;s[k];k++){switch(s[k])
以下程序的输出结果是______。voidfun(){staticinta=0;a+=2;printf("%d",a);}main(){intcc;for(cc=1;cc<4;cc
下面程序的运行结果是______。 #include<stdio.h> #include<string.h> fun(char*w,int n) { char t,*s1,*s2; s1=w;s2=w+n-1; while(s1<s2) {t=*s1++;
feof(fp)函数用来判断文件是否结束,如果遇到文件结束,则函数值为______,否则为______。
有如下程序 main() { int n=9; while(n>6){ n-; printf("%d",n); } } 该程序段的输出结果是______。
While、do-while语句是用于______基本结构。
以下叙述中正确的是
以下关于C语言的叙述中正确的是
随机试题
甲状腺功能减退的诊断主要依靠_______和FT4减低。
病毒性心肌炎患儿在恢复期限制其活动量的时间应不少于
急性左心衰可出现
患者,女,38岁。喉结右侧可及3cm×3cm×3cm肿物,表面光滑,质韧,无压痛,随吞咽上下移动。应首先老虑的是
柱下桩基如图:承台混凝土抗压强度fc=19.1MPa;按《建筑桩基技术规范》(JGJ94—94)计算承台长边受剪承载力,其值与()最接近。
四个全面战略布局指的是()。
F
American’sLeisureActivitiesLeisureactivities【T1】______.Bothmenandwomenreportedthat【T2】______.Visitingfriendsand
Somepeople,inallseriousness,saythathumanswillbelivinginspacewithinthenexthundredorsoyears.PlanetEarthwill
TherewasonceamaninSouthAmericawhohada【B1】______,apetbirdthatcould【B2】_____humanspeech.Theparrotwas【B3】______.
最新回复
(
0
)