Multiple Indirect : Pointer Unsafe « Language Basics « C# / C Sharp






Multiple Indirect

Multiple Indirect
/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/


using System; 
 
public class MultipleIndirect { 
  unsafe public static void Main() { 
    int x;    // holds a int value  
    int* p;  // holds an int pointer 
    int** q; // holds an pointer to an int pointer 
 
    x = 10; 
    p = &x; // put address of x into p 
    q = &p; // put address of p into q 
 
    Console.WriteLine(**q); // display the value of x  
  } 
}


           
       








Related examples in the same category

1.References and Pointers
2.Demonstrate pointers and unsafeDemonstrate pointers and unsafe
3.Demonstrate fixedDemonstrate fixed
4.Demonstrate the effects of pointer arithmethicDemonstrate the effects of pointer arithmethic
5.Demonstrate pointer comparisonDemonstrate pointer comparison
6.An array name with an index yields a pointer to the start of the arrayAn array name with an index yields a pointer to the 
   start of the array
7.Index a pointer as if it were an arrayIndex a pointer as if it were an array
8.Use fixed to get a pointer to the start of a stringUse fixed to get a pointer to the start of a string
9.Unsafe code: copyUnsafe code: copy
10.Pointers and Declarative Pinning
11.Unsafe ContextUnsafe Context