Visual Basic (VB) provide an easy-to-learn speech for web or desktop developers. Pointers are common variables in any language. A pointer "points" to a memory speak to location for a variable. The pointer allow you to update a variable's value outside of the bounds of the function. This is useful when you want to pass a pointer to a purpose and edit the variable located anywhere else in your code. To use a pointer in VB, you describe the pointer, assign it to a variable and pass it "by reference" in the function.
Instructions
Step1
Declare a variable and a pointer. In this instance, an integer inconsistent is declared. However, a pointer can point to any data type in your code (even another pointer). The following is how to announce these two variables:
Dim i As Integer
Dim i_ptr As Integer*
The asterisk denote a pointer patchy definition
Step2
Assign the figure value's lecture to to the pointer. The two morals are then "linked" together. Later in the code, a change to the pointer value changes the value in its assign address space. The following code assign the value:
i_ptr = AddressOf i
Step3
Change the value of the pointer and print out the results. observe when the pointer's value is misused, the value of i is changed also:
*i_ptr += 1
Console.WriteLine("The value of i is now {0}", i);
Console.WriteLine("The value of the i pointer i_ptr is also {0}", i_ptr);



Reply With Quote
Copyright Techfuels
Bookmarks