函数main()、test()的定义如下所示,调用函数test时,第一个参数采用传值方式,第二个参数采用传引用方式,main函数中"print(x,y)”执行后,输出结果为( )。

- A.1,5
- B.3,5
- C.7,5
- D.7,10
正确答案及解析
正确答案
解析
本题考察程序语言的基础知识。过程(或函数)首部声明的参数称为形式参数,简称形参;过程(或函数)调用时的参数称为实际参数,简称实参。
传值调用以实参向形式参数传递相应类型的值,在这种方式下,形式参数不能向实际参数返回信息。引用调用将实际参数的地址传递给形式参数,使得形参的地址就是对应的实参的地址,因此改变形参的值会改变实参的值。
在本题中,test(int x,int&a)x=5,a=1,经过test函数运算后,x=6,a=7,而返回时,因为a为引用调用,因此其会改变x的值,使得main函数的x值变为7,而y的值不发生变化,仍为5。答案选C。
包含此试题的试卷
你可能感兴趣的试题
( )is the process of transforming information so it is unintelligible to anyone but the intended recipient.
-
- A.Encryption
- B.Decryption
- C.Security
- D.Protection
- 查看答案
As each application module is completed,it undergoes( )to ensure that it operates correctly and reliably.
-
- A.unit testing
- B.integration testing
- C.system testing
- D.acceptance testing
- 查看答案
( )algorithm specifies the way to arrange data in a particular order.
-
- A.Search
- B.Random
- C.Sorting
- D.Merge
- 查看答案
After analyzing the source code,( )generates machine instructions that will carry out the meaning of the program at a later time.
-
- A.an interpreter
- B.a linker
- C.a compiler
- D.a converter
- 查看答案
( )can help organizations to better understand the information contained within the data and will also help identify the data that is most important to the business and future business decisions.
-
- A.Data processing system
- B.Big Data analytics
- C.Cloud computing
- D.Database management
- 查看答案