这里有一些想法。我正在学习,所以可能会出现错误,甚至缺少一些基本知识。 sizeof运算符返回字节数。 number of bits in byte是不恒定的值(纠正我,但它是char的位数)。 我想知道有多少位变量占用,sizeof不会告诉我,如果不作出关于char位数的假设。 于是我想出了这片(可能是不必要的)代码: #include <stdio.h>
#include <math.h>
我知道如何通过shell获取cpu或操作系统的位数。 cat /proc/cpuinfo | grep lm #-> get bit count of a cpu
uname -a #-> get bit count of an operation system
但是,我们如何获得C程序中的位数。 这是一个面试问题,我的解决方法是如下: int *ptr;
printf("%d\n