编写如下程序: Dim x As Integer, y As Integer, z As Integer Private Sub Command1_Click() Dim x As Integer x = 1: y = 2: z = 3

admin2015-10-23  33

问题 编写如下程序:
Dim x As Integer, y As Integer, z As Integer
Private Sub Command1_Click()
   Dim x As Integer
   x = 1: y = 2: z = 3
   z = fun_s(x)
   Print x; y; z
End Sub
Public Function fun_s(ByVal y As Integer) As Integer
   x = 5
   y = z + 1
   fun_s = x + y
End Function
程序运行后,单击命令按钮Command1,输出结果为

选项 A、4  2  9
B、1  2  9
C、5  2  9
D、5  4  9

答案B

解析 函数fun_s(ByVal y As Integer)是按值传递,返回一个整数。程序初始,定义x y z三个全局变量,x=y=z=0;Command1_Click 程序中,定义了局部变量x,并对局部变量x赋值为1,对全局变量y赋值为2,z赋值为3,调用fun_s函数,增加了一个局部变量y,全局变量x赋值为5,局部变量y =z+1=3+1=4,函数返回值为9,并将其返回值赋值给全局变量z。此时局部变量x为1,y为4。全局变量x,y,z分别为5,4,9。Print x;y;z结合其所在位置可知,要求输出局部变量x,全局变量y和z,结果为1,2,9,故选B项。
转载请注明原文地址:https://jikaoti.com/ti/1SJ0FFFM
0

最新回复(0)