int long longlong 大小 范围

在windows下 是 4 4 8

windows测试代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    printf("%d\n", sizeof(int));
    printf("%d\n", sizeof(long));
    printf("%d\n", sizeof(long long));
    return 0;
}

答案:

4
4
8

linux测试代码:

#include <stdio.h>

int main()
{
        printf("%d\n", sizeof(int));
        printf("%d\n", sizeof(long));
        printf("%d\n", sizeof(long long));
        return 0;
}

答案:

4
8
8

2 范围

#include <iostream>
#include <math.h>

using namespace std;

int main (int argc, char *argv[]) {
  int maxint = ~(1<<31);
  int t = pow(2,31)-1;
  cout<<maxint<<endl;
  cout<<t<<endl;

  int maxneg = (1<<31);
  t = pow(2, 31);
  cout<<maxneg<<endl;
  cout<<t<<endl;
  return 0;
}

结果:

2147483647
2147483647
-2147483648
-2147483648
文章目录