是什么在C / C ++的无符号长/长/ INT之间的区别? [英] What's the difference between unsigned long/long/int in c/c++?

查看:134
本文介绍了是什么在C / C ++的无符号长/长/ INT之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎所有的人都需要4个字节的空间,

It seems all of them take 4 bytes of space,

有啥区别?

推荐答案

首先,int的长度/长是不确定的。所以,你的编译器,一个 INT 可能是相同的,但是这不是跨编译器普及。

First of all, the size of int/long is unspecified. So on your compiler, an int and a long might be the same, but this isn't universal across compilers.

至于之间的差异无符号长

假设4个字节,一个 -2,147,483,648 2,147,483,647 <范围/ code>。一个unsigned long具有 0 向范围 4,294,967,295

Assuming 4 bytes, a long has the range of -2,147,483,648 to 2,147,483,647. An unsigned long has the range of 0 to 4,294,967,295.

另外一个区别是溢出。对于一个符号类型,溢出具有不确定的行为。但对于无符号类型,溢出是保证环绕。

One other difference is with overflow. For a signed type, an overflow has unspecified behavior. But for an unsigned type, overflow is guaranteed to "wrap around."

这篇关于是什么在C / C ++的无符号长/长/ INT之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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