窗体中有命令按钮Command1,事件过程如下: Public Function f(x As Integer)As Integer Dim y As Integer x=20 y=2 f=x*y End Function Private Sub Comm

admin2018-12-22  45

问题 窗体中有命令按钮Command1,事件过程如下:
Public Function f(x As Integer)As Integer
Dim y As Integer
x=20
y=2
f=x*y
End Function
Private Sub Command1_Click()
Dim y As Integer
Static x As Integer
x=10
y=5
y=f(x)
Debug.Print x;y
End Sub
运行程序,单击命令按钮,则立即窗口中显示的内容是(    )。

选项 A、10 5
B、10 40
C、20 5
D、20 40

答案D

解析 本题考查的是变量的作用域,程序中命令按钮中的x是用static定义的局部静态变量,只在模块的内部使用,过程执行时才可见。当调用f函数时,所求的f函数的值是f函数中x和y的值的乘积,即f函数的值是2*20=40,调用f函数后,原命令按钮中x的值被f函数的值覆盖,即x=20。最后输出x=20,y=40。
转载请注明原文地址:https://kaotiyun.com/show/2vMp777K
0

随机试题
最新回复(0)