A pointer is a variable type that allows you to refer indirectly to another object. Instead of holding data, a pointer holds the address to data -- the address of another variable or object. You can change the address value a pointer points to thus changing the variable or object the pointer is pointing to.
A reference is a type of pointer that cannot change and it must always point to a valid storage (no nulls).
Access VBA:
Not Supported
Same as VB Classic. Access VBA does not offer developer defined pointers.
ASP Classic:
Not Supported
ASP Classic does not offer developer defined pointers.
C#:
Although pointer data types in C# coding are less important than in other languages such as C++, C# does support developer defined pointers. Use the * operator to declare a pointer data type. Use the & operator to return the current address of a variable.
In .Net managed coding the use of pointers is not safe because the garbage collector may move memory around. To safely use pointers, use the unsafe keyword. However, avoid unsafe code if possible.
C++/CLI has more extensive support for pointers than C#. If you have needs that go beyond what C# offers, you can code in C++/CLI and add it to your project.
ObjectPAL doesn't have a developer defined pointer type except for use with DLLs where you use a special CPTR uses keyword to refer to a DLL string pointer data type.
The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.
Although pointer data types in Delphi coding are less important and not required for most general coding, Delphi fully supports developer defined pointers. Use a carrot (^) to declare a pointer data type. Use the @ operator or Addr function to return the current address of a variable.
Delphi provides typed pointer types such as PChar and PExtended as well as a generic point to anything Pointer type.
Nil is a special pointer value that you can assign to any type of pointer. Nil never points to any valid memory and indicates an unassigned or empty pointer.
Although pointer data types in Prism coding are less important than in other languages such as C++, Prism does support developer defined pointers. Use the ^ operator to declare a pointer data type. Use the @ operator to return the current address of a variable.
In .Net managed coding the use of pointers is not safe because the garbage collector may move memory around. To safely use pointers, use the unsafe keyword. However, avoid unsafe code if possible.
JavaScript does not offer developer defined pointers. However, you can use the eval function to simulate pointers.
Perl:
Perl supports both pointers and references.
PHP:
Not Supported
PHP supports references which allow you to refer to the value of a variable but PHP does not support true developer defined pointers. You cannot get and use the address of a variable.
However, you can still do inexpensive assignments by assigning by reference.
VB Classic:
Not Supported
VB6 does not officially offer developer defined pointers. However, VB5 and VB6 does have unsupported and undocumented VarPtr, StrPtr, and ObjPtr types but you probably should avoid them.
VB.Net doesn't support pointers. The closest it comes is IntPtr which you use to get pointer handles on windows, files, etc.
C# does have better support for pointers and C++/CLI has extensive support. One solution when it's really needed in VB.Net is to code in C# or C++/CLI and add it to your project.
The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.