单选题
下列程序运行后,单击窗体,在窗体上显示:1,1+2,1+2+3,1+2+3+4,1+2+3+4+5的和。在横线处应填写( )。 Private Sub Form_Click() Dim i As Integer,tt As Integer For i=1 To 5 tt=Sum(i):Print"tt=";tt, Next i End Sub Private Function Sum(________) __________ j=j+n:Sum=j End Function
A、
n As Integer j As Integer
B、
n As Integer Static j As Integer
C、
ByVal n AS Integer j As Integer
D、
ByVal n As Integer Static j As Integer
【正确答案】
D
【答案解析】
解析:本题考查参数的传递和静态局部变量。Sum函数在窗体单击事件中调用5次并用来求和,因此每一次求和结果应当保留,所以借助静态变量实现。同时要求传递的形参变化不应影响到实参,因此采用传值调用。
提交答案
关闭