问题 问答题 简答题

结构体数据作为参数在函数间传递有哪几种方式?请指出它们的异同点。

答案

参考答案:

结构体作为参数在函数之间进行传递主要有下 * * 种方式:

复制传递方式:把调用函数中结构体实参的值复制给被调用函数的形参构体。

地址传递方式:将调用函数中实参结构体的地址传递给被调用函数形参的结构体指针。

引用方式:被调用函数的形参应该说明为引用结构体变量形式。实际上,它是为实参结构化起一个别名。

另外,还可以通过全局变量的方式在函数间进行数据传递,但这种方式不好,增加函数之间的耦合性。

地址传递方式要比复制方式效率高。结构体复制传递方式需要对实参做一个备份,它把一个结构体变量作为参数传递,但要将结构体全部成员值一个一个传递,费时间又费空间,开销大。如果结构体的成员较多,则程序运行效率会大大降低,而采用地址传递方式将结构体变量的地址作为函数参数比较好,能提高运行效率。复制传递方式不影响调用函数实参的数值,而地址传递方式有可能影响实参的数值。

单项选择题
单项选择题

Recently, I flew to Las Vegas to attend a meeting. As we were about to arrive, the pilot announced with apology that there would be a slight (16) before setting down. High desert winds had (17) the airport to close all but one runway. He said that we would be (18) the city for a few minutes waiting to (19) . We were also told to remain in our seats meanwhile with our seat belts fastened (20) there might be a few bumps(颠簸). Well, that few minutes turned into about four-five minutes, including a ride that would make a roller coaster(过山车) (21) by comparison. The movement was so fierce that several passengers felt (22) and had to use airsickness bags. As you might guess, that’ s not a good thing to have happen in a(n) (23) space because it only (24) to increase the discomfort of the situation.

About twenty minutes into the adventure, the entire airplane became very (25) There was now a sense of anxiety and fear that could be (26) noticed. Every passenger simply held on for dear life …except one. A (27) was having a good time! With each bump of the (28) , he would let out a giggle (咯咯地笑)of delight. As I observed this, I (29) that he didn’t know he was supposed to be afraid and worried about his (30) . He neither thought about the past nor about the future. Those are what we gown--ups have learned from (31) . He was (32) the ride because he had not yet been taught to fear it. Having understood this, I took a deep breath and (33) back into my seat, pretending I was (34) on a roller coaster. I smiled for the rest of the flight. I even (35) to giggle once or twice, much to the chagrin(随恼) of the man sitting next to me holding the airsickness bag.

(32)()

A.learning

B.taking

C.missing

D.enjoying