char buff[] = {1, 2, 3, 4};
short *ptr = (short *) buff;
printf("%d", *ptr);

Ans: 1027

Short pointer increments by sizeof(short) i.e. 2 bytes. Thus after increment, the pointer will point to &buff[2]; Lower byte is 3. Upper byte is 4. Hex value becomes 0x0403.
Thus the Value: (4 * 256) + 3 = 1027.

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

floating point formatting, pointers, string vs integer pointer, long pointer increment, short pointer increment, short pointer increment, memory model, near, far and huge pointer, typed pointers and void pointer, sizeof void and void pointer,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan