- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to access array elements using a pointer in C#?
In C#, an array name and a pointer to a data type same as the array data, are not the same variable type. For example, int *p and int[] p, are not the same type. You can increment the pointer variable p because it is not fixed in memory but an array address is fixed in memory, and you can't increment that.
Here is an example −
Example
using System; namespace UnsafeCodeApplication { class TestPointer { public unsafe static void Main() { int[] list = {5, 25}; fixed(int *ptr = list) /* let us have array address in pointer */ for ( int i = 0; i < 2; i++) { Console.WriteLine("Address of list[{0}]={1}",i,(int)(ptr + i)); Console.WriteLine("Value of list[{0}]={1}", i, *(ptr + i)); } Console.ReadKey(); } } }
Output
Here is the output −
Address of list[0] = 31627168 Value of list[0] = 5 Address of list[1] = 31627172 Value of list[1] = 25
- Related Articles
- How to access elements of an array using pointer notation in C#?
- C++ Program to Access Elements of an Array Using Pointer
- How to access elements from a rectangular array in C#?
- How to access elements from jagged array in C#?
- How to access elements from an array in C#?
- How to access the pointer to structure in C language?
- How to access elements from multi-dimensional array in C#?
- Sum of array using pointer arithmetic in C++
- Sum of array using pointer arithmetic in C
- How to iterate through and access the JSON array elements using Rest Assured?
- Pointer to an Array in C
- How do we access elements from the two-dimensional array in C#?
- Explain the concept of Array of Pointer and Pointer to Pointer in C programming
- How to assign a pointer to function using C program?
- How to access Pandas Series elements by using indexing?

Advertisements