long long 和 long 和有什么不一样 [英] What's the difference between long long and long

查看:40
本文介绍了long long 和 long 和有什么不一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

long long 和 long 有什么区别?而且它们都不适用于 12 位数字 (600851475143),我是不是忘记了什么?

What's the difference between long long and long? And they both don't work with 12 digit numbers (600851475143), am I forgetting something?

#include <iostream>
using namespace std;

int main(){
  long long a = 600851475143;
}

推荐答案

按照标准,保证的是:

  • int 必须至少为 16 位
  • long 必须至少为 32 位
  • long long 必须至少为 64 位
  • int must be at least 16 bits
  • long must be at least 32 bits
  • long long must be at least 64 bits

在主要的 32 位平台上:

On major 32-bit platforms:

  • int 是 32 位
  • long 也是 32 位
  • long long 是 64 位
  • int is 32 bits
  • long is 32 bits as well
  • long long is 64 bits

在主要的 64 位平台上:

On major 64-bit platforms:

  • int 是 32 位
  • long 是 32 位或 64 位
  • long long 也是 64 位
  • int is 32 bits
  • long is either 32 or 64 bits
  • long long is 64 bits as well

如果您需要特定应用程序的特定整数大小,而不是相信编译器会选择您想要的大小,#include <stdint.h>(或 <cstdint>) 所以你可以使用这些类型:

If you need a specific integer size for a particular application, rather than trusting the compiler to pick the size you want, #include <stdint.h> (or <cstdint>) so you can use these types:

  • int8_tuint8_t
  • int16_tuint16_t
  • int32_tuint32_t
  • int64_tuint64_t
  • int8_t and uint8_t
  • int16_t and uint16_t
  • int32_t and uint32_t
  • int64_t and uint64_t

您可能还对#include <stddef.h>(或<cstddef>)感兴趣:

You may also be interested in #include <stddef.h> (or <cstddef>):

  • size_t
  • ptrdiff_t

这篇关于long long 和 long 和有什么不一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆