2016년 12월 15일 목요일

Pointer Operation

Valid pointer operations are assignment of pointers of the same type.


  • Possible Pointer Operation
1. adding or subtracting a pointer and an integer

2. subtracting or comparing two pointers to members of the same array

3. assigning or comparing to zero

All other pointer arithmetic is illegal except for 1~3.


  • Impossible Pointer Operation
1. add two pointers,

2. to multiply or divide or shift or mask

3. to add float or double

4. to assign a pointer of one type to a pointer of another type without a cast

※ except for void *


  • Pointer Operation Result Example
x86 system is 4byte pointer
x64 system is 8byte pointer

The example is x86 system. (but acutal system is x64 system)

integer 1 = 0x4



p2 = p1 + 4;
integer 4 is address 16(0xf) by pointer operation

p3 = p2 - p1
p3 is 4 by pointer operation but not 16(0xf)