Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 29th, 2012  |  syntax: None  |  size: 1.05 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. One last thing about C pointers: confused about what this snippet of code will do?
  2. void *a = //something;
  3.     *((unsigned **)((char*)b+4)) = a;
  4.        
  5. *((char *)b + 4) = a;
  6.        
  7. |----------|                                
  8.     |   b+4    |                            
  9.     |          |  1000                      
  10.     |   2000   |                            
  11.     |----------|                              
  12.           |                                          
  13.           |
  14.           |
  15.           |
  16.           -------------------->|----------|
  17.                                |   num    |
  18.           -------------------->|          |  2000
  19.           |                    |    2     |  This is what a points to  
  20.           |                    |----------|
  21.           |
  22.           |
  23.     |----------|                            
  24.     |     a    |                            
  25.     |          |  3000                      
  26.     |   2000   |                            
  27.     |----------|
  28.        
  29. int c;
  30. void * a = &c;
  31.  
  32. unsigned d;
  33. unsigned * e = &d;
  34. unsigned ** b = &e;
  35. b = (unsigned **)&a;