C“int"的大小是多少?2字节还是4字节?

编程入门 行业动态 更新时间:2024-10-12 18:20:38
本文介绍了C“int"的大小是多少?2字节还是4字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

C 中的 Integer 变量是占用 2 个字节还是 4 个字节?它取决于哪些因素?

Does an Integer variable in C occupy 2 bytes or 4 bytes? What are the factors that it depends on?

大多数教科书都说整数变量占用 2 个字节.但是当我运行一个打印整数数组的连续地址的程序时,它显示的差异是 4.

Most of the textbooks say integer variables occupy 2 bytes. But when I run a program printing the successive addresses of an array of integers it shows the difference of 4.

推荐答案

我知道它等于 sizeof(int).int 的大小实际上取决于编译器.在过去,当处理器是 16 位时,int 是 2 个字节.如今,在 32 位和 64 位系统上它通常是 4 个字节.

I know it's equal to sizeof(int). The size of an int is really compiler dependent. Back in the day, when processors were 16 bit, an int was 2 bytes. Nowadays, it's most often 4 bytes on a 32-bit as well as 64-bit systems.

不过,对于执行程序的特定系统,使用 sizeof(int) 是获取整数大小的最佳方法.

Still, using sizeof(int) is the best way to get the size of an integer for the specific system the program is executed on.

修正了在大多数 64 位系统上 int 是 8 个字节的错误声明.例如,在 64 位 GCC 上是 4 个字节.

Fixed wrong statement that int is 8 bytes on most 64-bit systems. For example, it is 4 bytes on 64-bit GCC.

更多推荐

C“int"的大小是多少?2字节还是4字节?

本文发布于:2023-11-25 10:33:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629408.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字节   大小   int   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!