c***2 发帖数: 838 | 1 In C.
Not sure whether this is an interesting or meaningless question. :-) |
i**********e 发帖数: 1145 | 2 a trick using pointer arithmetic.
(int)((int*)0+1)
一些常见面试题的答案与总结 -
http://www.ihas1337code.com |
H******7 发帖数: 1728 | 3 what does this mean, can you plz explain it?
【在 i**********e 的大作中提到】 : a trick using pointer arithmetic. : (int)((int*)0+1) : 一些常见面试题的答案与总结 - : http://www.ihas1337code.com
|
i**********e 发帖数: 1145 | 4 First, advance the pointer at address 0 by one. How many it advances depend
on the size of the pointer type.
一些常见面试题的答案与总结 -
http://www.ihas1337code.com |
y*********e 发帖数: 518 | 5 这个方法很妙!
depend
【在 i**********e 的大作中提到】 : First, advance the pointer at address 0 by one. How many it advances depend : on the size of the pointer type. : 一些常见面试题的答案与总结 - : http://www.ihas1337code.com
|
c***2 发帖数: 838 | 6 There are at least two other ways:
1) int a[2];
unsigned addr0=&a[0];
unsigned addr1=&a[1];
size_t sizeofint=addr1-addr0;
2) typedef struct ab {
int a;
int b;
} AB;
sizeofint=offset(b in AB)
=(unsigned)(&((AB*)0->b))
|