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

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 0.79 KB  |  hits: 7  |  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. Accessing elements in a static array using pointer(arithmetic) in C
  2. int A[5][5];
  3.   int i; int j;
  4.   for(i=0;i<5;i++){
  5.     for(j=0;j<5;j++){
  6.       A[i][j]=i+j;
  7.       printf("%dn", A[i][j]);
  8.     }
  9.   }
  10.        
  11. *(A+(2*5+2)*sizeof(int))?
  12.        
  13. *(*(A + 2) + 2)
  14.        
  15. a[i][j] == *(a[i] + j) == *(*(a + i) + j)
  16.        
  17. T *p;
  18.        
  19. int I = 0;
  20. float F = 0;
  21. double D = 0;
  22. int* PI = 0;
  23. float* PF = 0;
  24. double* PD = 0;
  25.  
  26. cout<<I<<" "<<F<<" "<<D<<" "<<PI<<" "<<PF<<" "<<PD<<endl;
  27. I++;F++;D++;PI++;PF++,PD++;
  28.  
  29. cout<<I<<" "<<F<<" "<<D<<" "<<PI<<" "<<PF<<" "<<PD<<endl;
  30. cout<<I<<" "<<F<<" "<<D<<" "<<(int)PI<<" "<<(int)PF<<" "<<(int)PD<<endl;
  31.        
  32. 0 0 0 0 0 0
  33. 1 1 1 0x4 0x4 0x8
  34. 1 1 1 4 4 8
  35.        
  36. void* V = 0;
  37.  
  38. int* IV = (int*)V;
  39. float* FV = (float*)V;
  40. double* DV = (double*)V;
  41.  
  42. IV++;FV++;DV++;
  43. cout<<IV<<" "<<FV<<" "<<DV<<endl;
  44.        
  45. 0x4 0x4 0x8