不使用sizeof,确定机器int大小

来源:互联网 发布:电气控制 视频软件 编辑:程序博客网 时间:2024/05/19 03:26
<pre name="code" class="cpp">#include<stdio.h>int main(){<span style="white-space:pre"></span>int i;<span style="white-space:pre"></span>unsignd int x = (unsigned int)~0;<span style="white-space:pre"></span>for (i = 1; x >>= 8; i++);<span style="white-space:pre"></span>printf("%d\n", i); }


<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></span>

#include<stdio.h>int main(){<span style="white-space:pre"></span>int a = 0;<span style="white-space:pre"></span>printf("%d",(char *)(&a + 1) - (char *)(&a));}





0 0
原创粉丝点击