内容正文:
编写说明:湖南省普通高校对口招生专业理论考试《计算机应用类专业综合考纲百套卷》,依据《湖南省普通高校对口招生计算机应用类专业综合知识基本要求及考试大纲》编写。每门课程均分三层训练:基础层(具象化支架)拆解考点为微目标,紧扣考纲 “掌握”“理解” 要求编写考点训练卷;巩固层(关联性支架)强化知识交叉与场景关联,按考纲专题编专题训练卷;应用层(引导性支架)聚焦真题突破,结合知识模块与教材编写课程综合卷。
本试卷是第82卷,按《计算机编程语言——C语言》范围和要求编写。具体内容为:①认识结构体;②定义结构体变量的方法;③typedef的使用;④引用结构体变量;⑤结构体变量的初始化;⑥同类型结构体变量间的赋值。
湖南省《计算机应用类专业综合考纲百套卷》 第82卷
《计算机编程语言——C语言》
结构体变量的定义和引用
考点训练卷
考试时间60分钟 满分100分
班级________姓名________学号________成绩________
一、单项选择题(本大题共20小题,每题2分,共40分)
1.下列关于 C 语言结构体的描述,错误的是( )
A. 结构体可以将多个不同数据类型的数据组合为一个整体
B. 结构体属于 C 语言的构造数据类型
C. 结构体定义完成后,会自动分配内存空间
D. 结构体中的成员可以是基本数据类型变量
2.现有结构体定义struct Stu{ int a; char b; };,以下定义结构体变量的方式,语法非法的是( )
A. struct Stu s1; B. struct { int a; char b; } s2;
C. Stu s3; D. struct Stu s4, s5;
3.执行代码片段,下列说法正确的是( )
struct Person{ int num; };
struct Person p1;
A. Person是结构体变量名 B. struct Person是结构体类型名
C. p1是结构体类型名 D. 定义后系统未分配任何内存
4.关于typedef关键字作用,下列说法正确的是( )
A. typedef可以创建新的数据类型
B. typedef仅为已有数据类型取别名
C. 使用typedef后原类型名无法再使用
D. typedef只能修饰基本数据类型
5.设有结构体struct A{ int m; float n; } a1;,若要引用成员m,正确的写法是( )
A. A.m B. a1->m C. a1.m D. struct A.m
6.以下结构体变量初始化语句,语法合法的是( )
struct Info{ int id; char ch; };
A. struct Info s1 = 10, 'A'; B. struct Info s2 = {10};
C. struct Info s3 = (10, 'A'); D. struct Info s4 = {10 'A'};
7.设有以下程序代码,运行后变量p.score的值为( )
#include <stdio.h>
struct Student{ int score; };
int main(){
struct Student p = {80};
struct Student q;
q = p;
q.score = 90; return 0; }
A. 80 B. 90 C. 随机值 D. 0
8.执行以下程序代码的输出结果是( )
#include <stdio.h>
struct Num{ int a; };
int main(){
struct Num x = {60};
if(x.a >= 60) printf("pass");
else printf("fail");
return 0; }
A. pass B. fail C. 无输出 D. 编译报错
9.设有以下代码,循环执行结束后,s.num的值为( )
#include <stdio.h>
struct Test{ int num; };
int main(){
struct Test s = {0};
int i;
for(i=1; i<=5; i++)
s.num = s.num + 1;
return 0; }
A. 0 B. 5 C. 6 D. 随机值
10.已有struct Man{ int id; }; struct Man m1={100}; struct Man m2;,执行m2=m1;后,m2.id的值是( )
A. 0 B. 100 C. 随机值 D. 编译错误
11.执行以下程序代码的输出结果是( )
#include <stdio.h>
typedef struct{ int a; int b; } Two;
int main(){
Two t = {10,20};
printf("%d", t.a + t.b);
return 0; }
A. 10 B. 20 C. 30 D. 编译报错
12.执行以下程序代码的输出结果是( )
#include <stdio.h>
struct Score{ int s; };
int main(){
struct Score sc = {75};
int res;
if(sc.s > 80) res = 1;
else res = 2;
printf("%d", res);
return 0; }
A. 1 B. 2 C. 75 D. 80
13.定义struct Box{ int w; int h; } b1={3,4},b2;,执行b2=b1;后,b2.w和b2.h的值依次是( )
A. 0,0 B. 3,4 C. 4,3 D. 随机值
14.执行以下程序代码的输出结果是( )
#include <stdio.h>
struct Num{ int n; };
int main(){
struct Num num = {1};
int cnt = 0;
while(num.n <= 3){
cnt++;
num.n++; }
printf("%d",cnt);
return 0; }
A. 1 B. 2 C. 3 D. 4
15.执行以下程序代码的输出结果是( )
#include <stdio.h>
struct A{ int x; };
void change(struct A a){
a.x = 100;}
int main(){
struct A m = {10};
change(m);
printf("%d",m.x);
return 0; }
A. 10 B. 100 C. 0 D. 编译错误
16. 执行以下程序代码,p.id 的值是( )
struct Info{
int id;};
void fun(struct Info t)
{ t.id = 999;}
int main()
{ struct Info p = {101};
fun(p);}
A. 999 B. 101 C. 0 D. 随机值
17. 执行以下程序代码,s.n 的值为( )
#include <stdio.h>
struct Num{
int n;};
int main()
{ struct Num s = {1};
int i;
for(i=1; i<4; i++)
s.n = s.n + i;}
A. 4 B. 6 C. 7 D. 10
18. 执行以下程序代码,c2.b 的值是( )
#include <stdio.h>
struct Cat{
int a;
int b;} c1 = {6};
int main()
{ struct Cat c2 = c1;
c2.b = c2.a + c2.b;}
A. 6 B. 12 C. 0 D. 随机值
19. 执行以下程序代码,s.sc 的值为( )
#include<stdio.h>
struct Score{
int sc;};
int main()
{ struct Score s = {70};
if(s.sc > 60)
s.sc = s.sc - 10;
else
s.sc = s.sc + 10;}
A. 60 B. 70 C. 80 D. 0
20. 执行以下程序代码,p2.price 的值为( )
#include<stdio.h>
struct Pen { int price; };
int main()
{ struct Pen p1 = {25}, p2;
p2 = p1;
p1.price = p1.price / 5;}
A. 5 B. 25 C. 0 D. 随机值
二、阅读程序,写出运行结果(本大题共20小题。每空3分,合计60分)
1.下列程序的运行结果是__________________。
#include <stdio.h>
struct Node
{ int x;
int y;};
struct Node func(struct Node t)
{ t.x += 5;
t.y -= 2;
return t;}
int main()
{ struct Node n1 = {10, 8};
struct Node n2;
n2 = func(n1);
printf("%d %d ", n1.x, n1.y);
printf("%d %d
", n2.x, n2.y);
return 0; }
2.下列程序的运行结果是__________________。
#include <stdio.h>
typedef struct
{ int score;
} Stu;
int main()
{ Stu s1 = {60};
Stu s2 = s1;
s1.score += 15;
if (s2.score >= 60)
s2.score = s2.score / 2;
printf("%d %d", s1.score, s2.score);
return 0; }
3.下列程序的运行结果是__________________。
#include <stdio.h>
struct Num
{ int n;};
int main()
{ struct Num num = {0};
int i;
for (i = 2; i <= 6; i += 2)
num.n += i;
printf("%d", num.n);
return 0; }
4.下列程序的运行结果是__________________。
#include <stdio.h>
typedef struct Two
{ int x;
int y;} TWO;
TWO getVal(TWO t)
{ t.x = t.x + t.y;
return t;}
int main()
{ TWO t1 = {5, 3};
TWO t2;
t2 = getVal(t1);
printf("%d", t1.x + t2.y);
return 0; }
5.下列程序的运行结果是__________________。
#include <stdio.h>
struct Score
{ int s1;
int s2;};
struct Score addScore(struct Score t)
{ t.s1 = t.s1 + 10;
return t;}
int main()
{ struct Score sc = {80, 90};
struct Score sc2 = addScore(sc);
printf("%d,%d", sc.s1, sc2.s1 + sc2.s2);
return 0; }
6.下列程序的运行结果是__________________。
#include <stdio.h>
typedef struct Tri
{ int x;} TRI;
int main()
{ TRI t = {0};
int j;
for (j = 1; j < 5; j++)
{ if (j % 2 == 1)
{ t.x += j; }
}
printf("%d", t.x);
return 0; }
7.下列程序的运行结果是__________________。
#include <stdio.h>
struct Id
{ int id;};
struct Id add(struct Id t1, struct Id t2)
{ struct Id res;
res.id = t1.id + t2.id;
return res;}
int main()
{ struct Id a = {15}, b = {25};
struct Id c = add(a, b);
printf("%d", c.id);
return 0; }
8.下列程序的运行结果是__________________。
#include <stdio.h>
typedef struct Num
{ int n;} NUM;
int main()
{ NUM num = {1};
int i = 2;
while(i <= 5)
{ num.n *= i;
i++; }
printf("%d", num.n);
return 0; }
9.下列程序的运行结果是__________________。
#include <stdio.h>
struct Temp
{ int t;};
struct Temp fun1(struct Temp x)
{ x.t = x.t + 6;
return x;}
int main()
{ struct Temp t1 = {3};
struct Temp t2 = fun1(t1);
struct Temp t3 = fun1(t2);
printf("%d %d", t2.t, t3.t);
return 0;}
10.下列程序的运行结果是__________________。
#include <stdio.h>
typedef struct
{ int total;} TOT;
void sub(TOT t)
{ t.total = t.total - 7;}
int main()
{ TOT t1 = {40};
TOT t2 = t1;
sub(t1);
t2.total = t2.total / 5;
printf("%d %d", t1.total, t2.total);
return 0; }
11.下列程序的运行结果是__________________。
#include <stdio.h>
struct Student
{ int score;
int rank;};
int main()
{ struct Student s1 = {78};
struct Student s2;
s2 = s1;
s1.rank = 12;
s2.score += 10;
printf("s1: %d %d
", s1.score, s1.rank);
printf("s2: %d %d
", s2.score, s2.rank);
return 0;}
12.下列程序的运行结果是__________________。
#include <stdio.h>
struct NumData
{ int x;
int y;};
int main()
{ struct NumData d1 = {9, 4};
struct NumData d2 = d1;
d1.x = d1.x / d1.y;
d2.y = d2.x + d2.y;
if (d1.x > d2.y)
{ printf("Big
"); }
else
{ printf("Small
"); }
printf("d1: %d %d
", d1.x, d1.y);
printf("d2: %d %d
", d2.x, d2.y);
return 0;}
13.下列程序的运行结果是__________________。
#include <stdio.h>
struct TwoVal
{ int a;
int b;};
typedef struct TwoVal TV;
TV calc(TV t1, TV t2)
{ TV temp;
temp.a = t1.a + t2.a;
temp.b = t1.b + t2.b;
return temp;}
int main()
{ TV t1 = {3, 5};
TV t2 = {2, 9};
TV t3 = calc(t1, t2);
printf("t3.a = %d, t3.b = %d
", t3.a, t3.b);
return 0;}
14.下列程序的运行结果是__________________。
#include <stdio.h>
struct Msg
{ int code;
int flag;};
int main()
{ struct Msg msg1 = {205};
struct Msg msg2 = msg1;
if (msg2.flag == 0)
{ msg2.code += 15; }
msg1.flag = 1;
printf("msg1: %d %d
", msg1.code, msg1.flag);
printf("msg2: %d %d
", msg2.code, msg2.flag);
return 0;}
15.下列程序的运行结果是__________________。
#include <stdio.h>
struct Total
{ int t;};
int main()
{ struct Total tot = {0};
int j = -1;
do
{ if (j > 0)
{ tot.t += j;}
j++;
} while (j <= 4);
printf("累加结果:%d
", tot.t);
return 0;}
16.下列程序的运行结果是__________________。
#include <stdio.h>
struct FinalTest
{ int x;
int y;};
struct FinalTest mix(struct FinalTest t)
{ t.x *= 2;
t.y += 3;
return t;}
int main()
{ struct FinalTest ft1 = {5, 8};
struct FinalTest ft2 = mix(ft1);
ft2 = ft1;
ft1.y -= 2;
printf("ft1: %d %d
", ft1.x, ft1.y);
printf("ft2: %d %d
", ft2.x, ft2.y);
return 0;}
17.下列程序的运行结果是__________________。
#include <stdio.h>
struct Person
{ int id;
int age;};
int main()
{ struct Person p1 = {1005, 22};
struct Person p2 = p1;
p1.age++;
p2.id--;
if(p1.age > p2.age)
printf("p1年龄更大
");
else
printf("p2年龄更大
");
printf("%d %d
", p1.id, p1.age);
printf("%d %d
", p2.id, p2.age);
return 0;}
18.下列程序的运行结果是__________________。
#include <stdio.h>
struct Math
{ int x;
int y;
} m1 = {23, 6};
int main()
{ int sum;
struct Math m2 = m1;
m1.x = m1.x / m1.y;
m2.y = m2.x * m2.y;
sum = m1.x + m2.y;
printf("sum=%d
", sum);
printf("%d %d
", m1.x, m1.y);
printf("%d %d
", m2.x, m2.y);
return 0; }
19.下列程序的运行结果是__________________。
#include <stdio.h>
struct Loop
{ int res;};
int main()
{ struct Loop lp = {1};
int i = 2;
while(i <= 6)
{ lp.res *= i;
i++; }
printf("%d
", lp.res);
return 0;}
20.下列程序的运行结果是__________________。
#include <stdio.h>
struct Range
{ int low;
int high;};
int main()
{ struct Range r1 = {4, 9};
struct Range r2 = r1;
int i;
for(i = r1.low; i <= r1.high; i++)
{ if(i % 2 == 0)
r2.low += i;}
printf("%d %d ", r1.low, r1.high);
printf("%d %d
", r2.low, r2.high);
return 0; }
原创精品资源学科网独家享有版权,侵权必究!
学科网(北京)股份有限公司
学科网(北京)股份有限公司
学科网(北京)股份有限公司
$
编写说明:湖南省普通高校对口招生专业理论考试《计算机应用类专业综合考纲百套卷》,依据《湖南省普通高校对口招生计算机应用类专业综合知识基本要求及考试大纲》编写。每门课程均分三层训练:基础层(具象化支架)拆解考点为微目标,紧扣考纲 “掌握”“理解” 要求编写考点训练卷;巩固层(关联性支架)强化知识交叉与场景关联,按考纲专题编专题训练卷;应用层(引导性支架)聚焦真题突破,结合知识模块与教材编写课程综合卷。
本试卷是第82卷,按《计算机编程语言——C语言》范围和要求编写。具体内容为:①认识结构体;②定义结构体变量的方法;③typedef的使用;④引用结构体变量;⑤结构体变量的初始化;⑥同类型结构体变量间的赋值。
湖南省《计算机应用类专业综合考纲百套卷》 第82卷
《计算机编程语言——C语言》
结构体变量的定义和引用
考点训练卷
考试时间60分钟 满分100分
班级________姓名________学号________成绩________
一、单项选择题(本大题共20小题,每题2分,共40分)
1.下列关于 C 语言结构体的描述,错误的是( )
A. 结构体可以将多个不同数据类型的数据组合为一个整体
B. 结构体属于 C 语言的构造数据类型
C. 结构体定义完成后,会自动分配内存空间
D. 结构体中的成员可以是基本数据类型变量
【答案】C
【解析】仅定义结构体类型时,不会分配内存,只有定义结构体变量后,系统才会为变量分配内存。
2.现有结构体定义struct Stu{ int a; char b; };,以下定义结构体变量的方式,语法非法的是( )
A. struct Stu s1; B. struct { int a; char b; } s2;
C. Stu s3; D. struct Stu s4, s5;
【答案】C
【解析】未使用typedef重命名时,必须带struct关键字定义结构体变量,C 写法缺少关键字,语法错误。
3.执行代码片段,下列说法正确的是( )
struct Person{ int num; };
struct Person p1;
A. Person是结构体变量名 B. struct Person是结构体类型名
C. p1是结构体类型名 D. 定义后系统未分配任何内存
【答案】B
【解析】struct Person为结构体类型,p1是结构体变量,定义变量后系统会为p1分配内存。
4.关于typedef关键字作用,下列说法正确的是( )
A. typedef可以创建新的数据类型
B. typedef仅为已有数据类型取别名
C. 使用typedef后原类型名无法再使用
D. typedef只能修饰基本数据类型
【答案】B
【解析】typedef功能是给现有类型起别名,不会创造新类型,原类型名依旧可用,也可用于结构体。
5.设有结构体struct A{ int m; float n; } a1;,若要引用成员m,正确的写法是( )
A. A.m B. a1->m C. a1.m D. struct A.m
【答案】C
【解析】普通结构体变量引用成员使用.运算符;->仅用于结构体指针。
6.以下结构体变量初始化语句,语法合法的是( )
struct Info{ int id; char ch; };
A. struct Info s1 = 10, 'A'; B. struct Info s2 = {10};
C. struct Info s3 = (10, 'A'); D. struct Info s4 = {10 'A'};
【答案】B
【解析】结构体初始化需用{}包裹,未初始化的成员自动赋默认值;A 缺少大括号,C 使用圆括号错误,D 成员间无逗号分隔。
7.设有以下程序代码,运行后变量p.score的值为( )
#include <stdio.h>
struct Student{ int score; };
int main(){
struct Student p = {80};
struct Student q;
q = p;
q.score = 90; return 0; }
A. 80 B. 90 C. 随机值 D. 0
【答案】A
【解析】q=p是整体赋值,两个变量相互独立,修改q的成员不会影响p。
8.执行以下程序代码的输出结果是( )
#include <stdio.h>
struct Num{ int a; };
int main(){
struct Num x = {60};
if(x.a >= 60) printf("pass");
else printf("fail");
return 0; }
A. pass B. fail C. 无输出 D. 编译报错
【答案】A
【解析】x.a值为 60,满足 if 条件,执行输出pass。
9.设有以下代码,循环执行结束后,s.num的值为( )
#include <stdio.h>
struct Test{ int num; };
int main(){
struct Test s = {0};
int i;
for(i=1; i<=5; i++)
s.num = s.num + 1;
return 0; }
A. 0 B. 5 C. 6 D. 随机值
【答案】B
【解析】循环执行 5 次,每次成员num自增 1,初始为 0,最终结果为 5。
10.已有struct Man{ int id; }; struct Man m1={100}; struct Man m2;,执行m2=m1;后,m2.id的值是( )
A. 0 B. 100 C. 随机值 D. 编译错误
【答案】B
【解析】同类型结构体变量支持直接整体赋值,m2所有成员和m1完全一致。
11.执行以下程序代码的输出结果是( )
#include <stdio.h>
typedef struct{ int a; int b; } Two;
int main(){
Two t = {10,20};
printf("%d", t.a + t.b);
return 0; }
A. 10 B. 20 C. 30 D. 编译报错
【答案】C
【解析】Two为结构体别名,变量t成员相加 10+20=30。
12.执行以下程序代码的输出结果是( )
#include <stdio.h>
struct Score{ int s; };
int main(){
struct Score sc = {75};
int res;
if(sc.s > 80) res = 1;
else res = 2;
printf("%d", res);
return 0; }
A. 1 B. 2 C. 75 D. 80
【答案】B
【解析】sc.s=75不满足大于 80 的条件,执行res=2,最终输出 2。
13.定义struct Box{ int w; int h; } b1={3,4},b2;,执行b2=b1;后,b2.w和b2.h的值依次是( )
A. 0,0 B. 3,4 C. 4,3 D. 随机值
【答案】B
【解析】同类型结构体整体赋值,b2完全复制b1的所有成员值。
14.执行以下程序代码的输出结果是( )
#include <stdio.h>
struct Num{ int n; };
int main(){
struct Num num = {1};
int cnt = 0;
while(num.n <= 3){
cnt++;
num.n++; }
printf("%d",cnt);
return 0; }
A. 1 B. 2 C. 3 D. 4
【答案】C
【解析】循环条件满足 3 次(1、2、3),cnt累加 3 次,最终值为 3。
15.执行以下程序代码的输出结果是( )
#include <stdio.h>
struct A{ int x; };
void change(struct A a){
a.x = 100;}
int main(){
struct A m = {10};
change(m);
printf("%d",m.x);
return 0; }
A. 10 B. 100 C. 0 D. 编译错误
【答案】A
【解析】结构体变量作为函数参数是值传递,函数内修改的是副本,不会影响原变量。
16. 执行以下程序代码,p.id 的值是( )
struct Info{
int id;};
void fun(struct Info t)
{ t.id = 999;}
int main()
{ struct Info p = {101};
fun(p);}
A. 999 B. 101 C. 0 D. 随机值
【答案】B
【解析】值传递特性,函数fun修改的是形参副本,主函数中实参p的值保持不变。
17. 执行以下程序代码,s.n 的值为( )
#include <stdio.h>
struct Num{
int n;};
int main()
{ struct Num s = {1};
int i;
for(i=1; i<4; i++)
s.n = s.n + i;}
A. 4 B. 6 C. 7 D. 10
【答案】C
【解析】初始s.n=1,循环执行 3 次:1+1=2、2+2=4、4+3=7。
18. 执行以下程序代码,c2.b 的值是( )
#include <stdio.h>
struct Cat{
int a;
int b;} c1 = {6};
int main()
{ struct Cat c2 = c1;
c2.b = c2.a + c2.b;}
A. 6 B. 12 C. 0 D. 随机值
【答案】A
【解析】c1部分初始化,c1.a=6、c1.b=0;c2拷贝后c2.a=6、c2.b=0,计算 6+0=6。
19. 执行以下程序代码,s.sc 的值为( )
#include<stdio.h>
struct Score{
int sc;};
int main()
{ struct Score s = {70};
if(s.sc > 60)
s.sc = s.sc - 10;
else
s.sc = s.sc + 10;}
A. 60 B. 70 C. 80 D. 0
【答案】A
【解析】70>60 条件成立,执行 70-10=60。
20. 执行以下程序代码,p2.price 的值为( )
#include<stdio.h>
struct Pen { int price; };
int main()
{ struct Pen p1 = {25}, p2;
p2 = p1;
p1.price = p1.price / 5;}
A. 5 B. 25 C. 0 D. 随机值
【答案】B
【解析】赋值完成后两变量独立,修改p1不会影响p2,p2.price保持 25 不变。
二、阅读程序,写出运行结果(本大题共20小题。每空3分,合计60分)
1.下列程序的运行结果是__________________。
#include <stdio.h>
struct Node
{ int x;
int y;};
struct Node func(struct Node t)
{ t.x += 5;
t.y -= 2;
return t;}
int main()
{ struct Node n1 = {10, 8};
struct Node n2;
n2 = func(n1);
printf("%d %d ", n1.x, n1.y);
printf("%d %d
", n2.x, n2.y);
return 0; }
【答案】10 8 15 6
2.下列程序的运行结果是__________________。
#include <stdio.h>
typedef struct
{ int score;
} Stu;
int main()
{ Stu s1 = {60};
Stu s2 = s1;
s1.score += 15;
if (s2.score >= 60)
s2.score = s2.score / 2;
printf("%d %d", s1.score, s2.score);
return 0; }
【答案】75 30
3.下列程序的运行结果是__________________。
#include <stdio.h>
struct Num
{ int n;};
int main()
{ struct Num num = {0};
int i;
for (i = 2; i <= 6; i += 2)
num.n += i;
printf("%d", num.n);
return 0; }
【答案】12
4.下列程序的运行结果是__________________。
#include <stdio.h>
typedef struct Two
{ int x;
int y;} TWO;
TWO getVal(TWO t)
{ t.x = t.x + t.y;
return t;}
int main()
{ TWO t1 = {5, 3};
TWO t2;
t2 = getVal(t1);
printf("%d", t1.x + t2.y);
return 0; }
【答案】8
5.下列程序的运行结果是__________________。
#include <stdio.h>
struct Score
{ int s1;
int s2;};
struct Score addScore(struct Score t)
{ t.s1 = t.s1 + 10;
return t;}
int main()
{ struct Score sc = {80, 90};
struct Score sc2 = addScore(sc);
printf("%d,%d", sc.s1, sc2.s1 + sc2.s2);
return 0; }
【答案】80,180
6.下列程序的运行结果是__________________。
#include <stdio.h>
typedef struct Tri
{ int x;} TRI;
int main()
{ TRI t = {0};
int j;
for (j = 1; j < 5; j++)
{ if (j % 2 == 1)
{ t.x += j; }
}
printf("%d", t.x);
return 0; }
【答案】4
7.下列程序的运行结果是__________________。
#include <stdio.h>
struct Id
{ int id;};
struct Id add(struct Id t1, struct Id t2)
{ struct Id res;
res.id = t1.id + t2.id;
return res;}
int main()
{ struct Id a = {15}, b = {25};
struct Id c = add(a, b);
printf("%d", c.id);
return 0; }
【答案】40
8.下列程序的运行结果是__________________。
#include <stdio.h>
typedef struct Num
{ int n;} NUM;
int main()
{ NUM num = {1};
int i = 2;
while(i <= 5)
{ num.n *= i;
i++; }
printf("%d", num.n);
return 0; }
【答案】120
9.下列程序的运行结果是__________________。
#include <stdio.h>
struct Temp
{ int t;};
struct Temp fun1(struct Temp x)
{ x.t = x.t + 6;
return x;}
int main()
{ struct Temp t1 = {3};
struct Temp t2 = fun1(t1);
struct Temp t3 = fun1(t2);
printf("%d %d", t2.t, t3.t);
return 0;}
【答案】9 15
10.下列程序的运行结果是__________________。
#include <stdio.h>
typedef struct
{ int total;} TOT;
void sub(TOT t)
{ t.total = t.total - 7;}
int main()
{ TOT t1 = {40};
TOT t2 = t1;
sub(t1);
t2.total = t2.total / 5;
printf("%d %d", t1.total, t2.total);
return 0; }
【答案】40 8
11.下列程序的运行结果是__________________。
#include <stdio.h>
struct Student
{ int score;
int rank;};
int main()
{ struct Student s1 = {78};
struct Student s2;
s2 = s1;
s1.rank = 12;
s2.score += 10;
printf("s1: %d %d
", s1.score, s1.rank);
printf("s2: %d %d
", s2.score, s2.rank);
return 0;}
【答案】
s1: 78 12
s2: 88 0
12.下列程序的运行结果是__________________。
#include <stdio.h>
struct NumData
{ int x;
int y;};
int main()
{ struct NumData d1 = {9, 4};
struct NumData d2 = d1;
d1.x = d1.x / d1.y;
d2.y = d2.x + d2.y;
if (d1.x > d2.y)
{ printf("Big
"); }
else
{ printf("Small
"); }
printf("d1: %d %d
", d1.x, d1.y);
printf("d2: %d %d
", d2.x, d2.y);
return 0;}
【答案】
Small
d1: 2 4
d2: 9 13
13.下列程序的运行结果是__________________。
#include <stdio.h>
struct TwoVal
{ int a;
int b;};
typedef struct TwoVal TV;
TV calc(TV t1, TV t2)
{ TV temp;
temp.a = t1.a + t2.a;
temp.b = t1.b + t2.b;
return temp;}
int main()
{ TV t1 = {3, 5};
TV t2 = {2, 9};
TV t3 = calc(t1, t2);
printf("t3.a = %d, t3.b = %d
", t3.a, t3.b);
return 0;}
【答案】t3.a = 5, t3.b = 14
14.下列程序的运行结果是__________________。
#include <stdio.h>
struct Msg
{ int code;
int flag;};
int main()
{ struct Msg msg1 = {205};
struct Msg msg2 = msg1;
if (msg2.flag == 0)
{ msg2.code += 15; }
msg1.flag = 1;
printf("msg1: %d %d
", msg1.code, msg1.flag);
printf("msg2: %d %d
", msg2.code, msg2.flag);
return 0;}
【答案】
msg1: 205 1
msg2: 220 0
15.下列程序的运行结果是__________________。
#include <stdio.h>
struct Total
{ int t;};
int main()
{ struct Total tot = {0};
int j = -1;
do
{ if (j > 0)
{ tot.t += j;}
j++;
} while (j <= 4);
printf("累加结果:%d
", tot.t);
return 0;}
【答案】累加结果:10
16.下列程序的运行结果是__________________。
#include <stdio.h>
struct FinalTest
{ int x;
int y;};
struct FinalTest mix(struct FinalTest t)
{ t.x *= 2;
t.y += 3;
return t;}
int main()
{ struct FinalTest ft1 = {5, 8};
struct FinalTest ft2 = mix(ft1);
ft2 = ft1;
ft1.y -= 2;
printf("ft1: %d %d
", ft1.x, ft1.y);
printf("ft2: %d %d
", ft2.x, ft2.y);
return 0;}
【答案】
ft1: 5 6
ft2: 5 8
17.下列程序的运行结果是__________________。
#include <stdio.h>
struct Person
{ int id;
int age;};
int main()
{ struct Person p1 = {1005, 22};
struct Person p2 = p1;
p1.age++;
p2.id--;
if(p1.age > p2.age)
printf("p1年龄更大
");
else
printf("p2年龄更大
");
printf("%d %d
", p1.id, p1.age);
printf("%d %d
", p2.id, p2.age);
return 0;}
【答案】
p1年龄更大
1005 23
1004 22
18.下列程序的运行结果是__________________。
#include <stdio.h>
struct Math
{ int x;
int y;
} m1 = {23, 6};
int main()
{ int sum;
struct Math m2 = m1;
m1.x = m1.x / m1.y;
m2.y = m2.x * m2.y;
sum = m1.x + m2.y;
printf("sum=%d
", sum);
printf("%d %d
", m1.x, m1.y);
printf("%d %d
", m2.x, m2.y);
return 0; }
【答案】
sum=141
3 6
23 138
19.下列程序的运行结果是__________________。
#include <stdio.h>
struct Loop
{ int res;};
int main()
{ struct Loop lp = {1};
int i = 2;
while(i <= 6)
{ lp.res *= i;
i++; }
printf("%d
", lp.res);
return 0;}
【答案】720
20.下列程序的运行结果是__________________。
#include <stdio.h>
struct Range
{ int low;
int high;};
int main()
{ struct Range r1 = {4, 9};
struct Range r2 = r1;
int i;
for(i = r1.low; i <= r1.high; i++)
{ if(i % 2 == 0)
r2.low += i;}
printf("%d %d ", r1.low, r1.high);
printf("%d %d
", r2.low, r2.high);
return 0; }
【答案】4 9 22 9
原创精品资源学科网独家享有版权,侵权必究!
学科网(北京)股份有限公司
学科网(北京)股份有限公司
学科网(北京)股份有限公司
$