Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Call By Value & Call By Reference

Aim:
To find the swapping of the given numbers using visual basic .net
console application

codings
Module Module1

Public Sub swapval(ByVal x As Integer, ByVal y As Integer)


Dim t As Integer
t=x
x=y
y=t
End Sub

Public Sub swapref(ByRef x As Integer, ByRef y As Integer)


Dim t As Integer
t=x
x=y
y=t
End Sub

Public Function fact(ByVal x As Integer) As Integer


Dim i, mani As Integer
mani = 1
For i = 1 To x
mani = mani * i
Next
fact = mani
Return fact
End Function

Sub Main()
Dim a, b, f As Integer
Console.WriteLine("enter a")
a = Console.ReadLine()
Console.WriteLine("enter b")
b = Console.ReadLine()
Console.WriteLine("call by value")
Call swapval(a, b)
Console.WriteLine("a={0},b={1}", a, b)
Console.WriteLine("call by ref")
Call swapref(a, b)
Console.WriteLine("a={0},b={1}", a, b)
Console.ReadLine()
Console.WriteLine("enter to find the fact")
f = Console.ReadLine
Console.WriteLine("factorial is={0}", fact(f))
Console.ReadLine()
End Sub
End Module

Output:

You might also like