由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Figure out size of int without using sizeof()
相关主题
another C interview question紧急求救:calculate analogous figures for
离奇的Amzaon第一轮电面我的bloomberg肯定没戏了,发点面试题攒人品吧
砸了面试,发面题CS 面试题总结(5)
google电面第一轮面经 求bless看一道面试题
看到一个c的面试题,求教。给大家看几道C 小程序
来贡献个小题.问一个关于xor的题
一道码公电面题(nvidia),怎么做算法题目一问
nvidia面试题onsite完,攒rp系列(二)
相关话题的讨论汇总
话题: int话题: ab话题: figure话题: size话题: sizeof
进入JobHunting版参与讨论
1 (共1页)
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))
1 (共1页)
进入JobHunting版参与讨论
相关主题
onsite完,攒rp系列(二)看到一个c的面试题,求教。
一道 C++ 的题。来贡献个小题.
一道C面试题一道码公电面题(nvidia),怎么做
有疑问的一题nvidia面试题
another C interview question紧急求救:calculate analogous figures for
离奇的Amzaon第一轮电面我的bloomberg肯定没戏了,发点面试题攒人品吧
砸了面试,发面题CS 面试题总结(5)
google电面第一轮面经 求bless看一道面试题
相关话题的讨论汇总
话题: int话题: ab话题: figure话题: size话题: sizeof