Home > Backend Development > C#.Net Tutorial > What are pointers in C#?

What are pointers in C#?

王林
Release: 2023-09-02 11:49:02
forward
1464 people have browsed it

C# 中的指针是什么?

A pointer is a variable whose value is the address of another variable, which is the direct address of a memory location.

The syntax for a pointer is -

type *var-name;
Copy after login

Here's how to declare a pointer type -

double *z; /* pointer to a double */
Copy after login

C# allows the use of pointer variables in functions or blocks of code marked by the unsafe modifier. Unsafe code or unmanaged code is a block of code that uses pointer variables.

The following is our module showing how to declare and use pointer variables. We have used the unsafe modifier here -

static unsafe void Main(string[] args) {
   int val = 50;
   int* x = &val;

   Console.WriteLine("Data: {0} ", val);
   Console.WriteLine("Address: {0}", (int)x);
   Console.ReadKey();
}
Copy after login

The above is the detailed content of What are pointers in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template