两道面试题

ithiker 2013-11-05 12:50:33
1.int(((int*)0)+4));结果是多少,为什么?
2.有t1,t2,t3三个表,均可能含有主键a,用sql语句找出t1中主键为a的记录,但该记录不同时出现在t2和t3中
...全文
280 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lunat 2013-11-05
  • 打赏
  • 举报
回复
少一个括号,否则在32位机器上是16,64位机器上32;
帝国队长 2013-11-05
  • 打赏
  • 举报
回复
学习了,大家都是高手啊,第一题我都不会。
一根烂笔头 2013-11-05
  • 打赏
  • 举报
回复
1.

783 #define container_of(ptr, type, member) ({                      \
784         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
785         (type *)( (char *)__mptr - offsetof(type,member) );})
786 
linux核心的类似用法。 int指针占用4B,加上4,就是偏移4*4=16B,取其整数
modyaj 2013-11-05
  • 打赏
  • 举报
回复
引用 3 楼 gigglesun 的回复:
[quote=引用 2 楼 qq120848369 的回复:] 第一个是偏移4个int的地址吧,16 第二个用not exist可以解决吧,select * from t1 where not exist(select * from t2,t3 where t2.key=t3.key and t1.key=t2.key)
第一题我是这样理解的,((int*)0+4)表示将0转换为地址,在这个基础上偏移4个int的地址,然后在偏移后地址上取一个int值,因而值是未知的,看上去应该是这样呀?[/quote] 不是 4个int类型的字节大小么?依赖于系统,但也算是已知的吧!
ithiker 2013-11-05
  • 打赏
  • 举报
回复
引用 2 楼 qq120848369 的回复:
第一个是偏移4个int的地址吧,16 第二个用not exist可以解决吧,select * from t1 where not exist(select * from t2,t3 where t2.key=t3.key and t1.key=t2.key)
第一题我是这样理解的,((int*)0+4)表示将0转换为地址,在这个基础上偏移4个int的地址,然后在偏移后地址上取一个int值,因而值是未知的,看上去应该是这样呀?
qq120848369 2013-11-05
  • 打赏
  • 举报
回复
第一个是偏移4个int的地址吧,16 第二个用not exist可以解决吧,select * from t1 where not exist(select * from t2,t3 where t2.key=t3.key and t1.key=t2.key)

69,335

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧