问题 单项选择题

单击一次命令按钮后,下列程序的执行结果是( )。  Private Sub Command1_Click()   s=P(1) +P(2) +P(3) +P(4)   Print s  End Sub  Public Function P(N As Integer)   Static Sum   For i=1 To N   Sum=Sum+i   Next i   P=Sum  End Function

A.1 1 * #

B.1 1 * #

C.1 1 * #1 1 * # 1 2 * #

D.1 1 * #1 1 * ##  1 2 * ##

答案

参考答案:D

解析:当i=1时,调用函数过程DS,由于y,n为静态变量值保存,执行x =x+1;y=y + 1后x=1,y=1执行m=m &"*":n=n&"#"后,m="*",n ="#";当I=2时同上,只是y=2,n="##"。输出结果如选项D)所示。

填空题
单项选择题