VB类题目求为什么是这个结果本人运行下就知道答案
来源:百度知道 编辑:UC知道 时间:2024/06/14 17:49:39
Private Sub Command1_Click()
Dim b As Integer
a = 1: b = 2
Print fun1(fun1(a, b), b)
Print a
Print b
End Sub
Private Function fun1(x As Integer, y As Integer) As Integer
Dim i As Integer
For i = 1 To y
y = y + 1
x = x + 1
a = x + y
Next i
fun1 = a + y
End Function
答案是34
26
8
不知道为什么找高手!!!
Dim b As Integer
a = 1: b = 2
Print fun1(fun1(a, b), b)
Print a
Print b
End Sub
Private Function fun1(x As Integer, y As Integer) As Integer
Dim i As Integer
For i = 1 To y
y = y + 1
x = x + 1
a = x + y
Next i
fun1 = a + y
End Function
答案是34
26
8
不知道为什么找高手!!!
在函数fun1中,因为x、y的形式参数值是默认byref类型的传址方式(如果声明byval,则实际参数a、b的值不会被改变),也就是调用后,x、y的值如果有改变,会分别传到调用后的实际参数a、b中
代入后,耐心的分析一下吧,大家都是这么过来的,相信你能分析出来,加油
二楼,你没注意到a的定义没有吗?a是通用变量,dim a as integer,楼主给的结果是对的
运行结果是:
31
3
8
楼主是不是搞错了吖?