Pointer arithmetic : Pointer : Unsafe C# Examples


C# Examples » Unsafe » Pointer »

 

Pointer arithmetic









    
using  System;  
  
class  MainClass  {  
    unsafe  public  static  void  Main()  {  
        int[]  nums  =  new  int[10];  
  
        Console.WriteLine("\nUse  pointer  arithmetic.");  
        fixed  (int*  p  =  nums)  {  
            for(int  i=0;  i  <  10;  i++)    
                *(p+i)  =  i;
  
            for(int  i=0;  i  <  10;  i++)    
                Console.WriteLine("*(p+{0}):  {1}  ",  i,  *(p+i));  
        }  
    }  
}
    
   
  
   



Output

Use pointer arithmetic.
*(p+0): 0
*(p+1): 1
*(p+2): 2
*(p+3): 3
*(p+4): 4
*(p+5): 5
*(p+6): 6
*(p+7): 7
*(p+8): 8
*(p+9): 9


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Unsafe
» Pointer