变量占的字节数

32位机 int 4字节 short int 2字节 

一个int占多少个字节?

这个问题我们往往得到的答案是4.

但是int到底占多少个字节,却跟你的机器环境有关.

  1. As you can see, the typical data type sizes match the ILP32LL model, which is what most compilers adhere to on 32-bit platforms. The LP64 model is the de facto standard for compilers that generate code for 64-bit platforms.  

最近在一本有关代码审计的书上看到如上解释.这里很好的解释了int到底应该占多少个字节.

而且从他的角度来看是编译器去适应平台.所以真正决定int占多少字节取决于你的device platforms.

其实无论哪种模型short和char无论哪种model下都保持一致.

我们见得最多的就是ILP32LL模型.这种模型下int和long已经pointer占4个字节 long long占8个字节.


PS:这个表很容易记,中间的数字表明你是64bit还是32bit的机器.前面的I表示int,L表示long,LL表示long long,P就表示pointer.

位于数字前面的类型表示跟中间的bit数保持一致.举个例子:ILP32LL 就是ILP是32位,LL是64位.


关于printf函数输出先后顺序的讲解!!

对于printf函数printf("%d%d ",a,b);函数的实际输出顺序是这样的
先计算出b,然后在计算a,接着输出a,最后在输出b;
例子如下:
#include<iostream>
using namespace std;
int main()
{
 int i=3,j=5;
 printf("%d  %d ",(i++)-(--j),j=(i+=2));
 printf("%d  %d ",i,j);
  return 0;
}
     此题的执行过程如下;
   首先对于第一个printf先计算出j=(i+=2),这样此时i=i+2=5,j=5;
   接着计算(i++)-(--j)=(5)-(4)=1,注意在计算完之后令i++,及i=6;


原文地址:https://www.cnblogs.com/didi520/p/4165485.html