- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are pointers in C#?
Pointer is a variable whose value is the address of another variable i.e., the direct address of the memory location.
The syntax of a pointer is −
type *var-name;
The following is how you can declare a pointer type −
double *z; /* pointer to a double */
C# allows using pointer variables in a function of code block when it is marked by the unsafe modifier. The unsafe code or the unmanaged code is a code block that uses a pointer variable.
The following is our module showing how to declare and use a pointer variable. We have used 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(); }
Advertisements