fork download
  1. #include <stdio.h>
  2.  
  3. int x[3][5] =
  4. {
  5. { 1, 2, 3, 4, 5 },
  6. { 6, 7, 8, 9, 10 },
  7. { 11, 12, 13, 14, 15 }
  8. };
  9.  
  10. int (*pArr35)[3][5] = &x;
  11. // &x is a pointer to an array of 3 arrays of 5 ints.
  12.  
  13. int (*pArr5a)[5] = x;
  14. // x decays from an array of arrays of 5 ints to
  15. // a pointer to an array of 5 ints,
  16. // x is a pointer to an array of 5 ints.
  17.  
  18. int (*pArr5b)[5] = &x[0];
  19. // &x[0] is a pointer to 0th element of x,
  20. // x[0] is an array of 5 ints,
  21. // &x[0] is a pointer to an array of 5 ints.
  22.  
  23. int *pInta = x[0];
  24. // x[0] is 0th element of x,
  25. // x[0] is an array of 5 ints,
  26. // x[0] decays from an array of 5 ints to
  27. // a pointer to an int.
  28.  
  29. int *pIntb = *x;
  30. // x decays from an array of arrays of 5 ints to
  31. // a pointer to an array of 5 ints,
  32. // x is a pointer to an array of 5 ints,
  33. // *x is an array of 5 ints,
  34. // *x decays from an array of 5 ints to
  35. // a pointer to an int.
  36.  
  37. int *pIntc = &x[0][0];
  38. // x[0][0] is 0th element of x[0],
  39. // where x[0] is an array of 5 ints,
  40. // x[0][0] is an int,
  41. // &x[0][0] is a pointer to an int.
  42.  
  43. int main(void)
  44. {
  45. printf("&x=%p x=%p &x[0]=%p x[0]=%p *x=%p &x[0][0]=%p\n",
  46. pArr35, pArr5a, pArr5b, pInta, pIntb, pIntc);
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.01s 1676KB
stdin
Standard input is empty
stdout
&x=0x804a040 x=0x804a040 &x[0]=0x804a040 x[0]=0x804a040 *x=0x804a040 &x[0][0]=0x804a040