编写如下程序: Private Sub Commandl_Click() Dim m As Integer,n As Integer n=2 For m=1 To 3 Print proc(n);

admin2018-10-15  19

问题 编写如下程序:
Private Sub Commandl_Click()
    Dim m As Integer,n As Integer
    n=2
    For m=1 To 3
            Print proc(n);
    Next m
End Sub
Function proc(i As Integer)
    Dim a As Integer,Static b As Integer
    a=a+1:b=b+1
    proc=a*b+i
End Function
程序运行后,单击命令按钮Commandl,输出结果为

选项 A、3 3 3
B、3 4 5
C、3 5 6
D、1 2 3

答案B

解析 使用Dim关键字定义的是动态局部变量,过程执行结束后即被释放;使用Static关键字定义的是静态局部变量,过程执行结束后仍然保留。本题中函数proc中的局部变量a是动态变量,b是静态变量。即每次函数调用后b的值会保留。先后三次调用proc(n)方法,依次输出3、4、5。
转载请注明原文地址:https://kaotiyun.com/show/0UFp777K
0

相关试题推荐
最新回复(0)