有下面程序代码: Private Sub Command1_Click() Dim x As Integer, s As Integer x = 1 For k = 1 To 3 x = x + 1

admin2018-12-20  31

问题 有下面程序代码:
Private Sub Command1_Click()
    Dim x As Integer, s As Integer
    x = 1
    For k = 1 To 3
        x = x + 1
        proc x
        s = s + x
    Next k
    Print s
End Sub
Private Sub proc(ByVal a As Integer)
    Static x As Integer
    x = x + 1
    a = a + x
End Sub
程序运行后,单击命令按钮Command1,输出结果是

选项 A、6
B、9
C、15
D、19

答案B

解析 ByVal表示参数传递时是值传递。不改变实参的值。Command1_Click事件中proc x语句不改变x的值。因此可直接按照for循环的规律计算s的值。选B)。
转载请注明原文地址:https://kaotiyun.com/show/kkFp777K
0

最新回复(0)