In this article, you will learn about pointers and unsafe code in C#.
What is a Pointer? “A pointer is a variable that holds the memory address of another variable”. In very short term, we can say that a “pointer is a memory address”. The address, that a pointer variable holds, directly points to the value stored in memory and that value is assigned to another variable which is not a pointer. That’s why we call them pointers (they point). What is an Unsafe code in C#? In C#, an unsafe code is a block of code that does not run under the control of CLR. Unsafe code actually is a block of code that includes pointers. So, in C#, pointers are unsafe. Before we start discussing why pointers are unsafe, you should be aware of some common terms. CLR, Managed Code and Unmanaged Code. What is CLR? CLR is common language runtime that controls the execution of .net programs from loading into memory to exception handling and type safety. CLR also provides a Debug Engine, Garbage Collector, Thread Management and many other features for handling the execution of C# programs and other .NET based programming languages. When you install .NET Framework on your computer, you basically install two main components of .NET.
To perform increment or decrements on a pointer we use increment operator (++) and decrement operator (--). Void* pointers cannot be incremented are decremented because they do not have any underlying type but increment and decrement on pointers depends on size of underlying type, now let me explain you that part of puzzle.
First Example of java