[Solved] Advance Programming in c


  1. *(num+1)[1] and **(num+2) are different ways of writing the same thing. That is, the third element of num.
  2. The type of num is short (*)[2]. That is, it is a pointer to an array of 2 short values.

With these two facts in mind we can work out what the code is doing. Below assumes a 32 bit system for simplicity.

  • num+1. Since num points to two short values, using pointer arithmetic, num+1 will be 4 bytes (2 shorts) after num.
  • (num+1)[1]. The array index gives the second element starting from num+1. That means another 4 bytes past num+1 and hence 8 bytes past num.
  • Accessing 8 bytes after num gives exactly 15.

0

solved Advance Programming in c