设窗体上有一个Command1命令按钮,还有以下程序代码: Private Sub Command1_Click() Private Sub proc(a As Integer) Static x As Integer Static x As Inte

admin2020-04-18  18

问题 设窗体上有一个Command1命令按钮,还有以下程序代码:
Private Sub Command1_Click()  Private Sub proc(a As Integer)
Static x As Integer  Static x As Integer
x=x+1  x=x+a:a=x
Call proc(x)  End Sub
Print x,
End Sub
程序运行后,3次单击命令按钮,则产生的输出是

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

答案C

解析 本题在Command1 click过程中和Sub过程proc中分别定义了一个静态变量x,这两个x都是局部变量,隶属于不同的局部,互不干涉;当单击命令按钮时,单击事件中的x加1,然后调用proc过程:由于proc的形参a采用地址传递,因此对a的改变会影响实参x。三次单击按钮分别使得两个过程中的x分别交化,都会保留上一次过程结束时的值。
转载请注明原文地址:https://kaotiyun.com/show/0pTp777K
0

最新回复(0)