How many bytes is the int type?

Source: Internet
Author: User

Today found that the neon technology in the number of int type of bytes is 2, it is very strange, the first to write 51 single-chip machine is also 2, and then to the idea of a transition to 4, now have encountered 2.

One, transfer from HTTP://WWW.TUICOOL.COM/ARTICLES/6J2UQI2

I've been looking at a deep understanding of the computer system, which refers to the 32-bit machine and the 64 machine in which the int type occupies 4 bytes. Later, checked the C programming language this book, there is a sentence is like this: Each compiler are free to choose appropriate sizes for its own hardware, SUBJ ECT only to the restriction which shorts and ints are at least 16bits, longs are in least 32bits, and short are no longer th An int, which is no longer than Long. The meaning is roughly the compiler can choose the appropriate size according to its own hardware, but it needs to satisfy the constraint: the short and int types are at least 16 bits long, at least 32 bits, and the short length cannot exceed the int type, and the int cannot exceed the long type. This means that each type of variable length is determined by the compiler, while the current mainstream compiler is typically a 32-bit machine and a 64-bit machine in which the int type is 4 bytes (for example, GCC). The following lists the number of bytes for each type of 32-bit machine and 64-bit machine under the GCC compiler:

Type C 32 64
Char 1 1
Short int 2 2
Int 4 4
Long int 4 8
Long Long int 8 8
char* 4 8
Float 4 4
Double 8 8

Note that the pointer type stores the address of the variable, so the 32-bit machine only needs 32bit, and the 64-bit machine needs 64bit.

The above article from: http://charlesxie.blog.51cto.com/2236179/939680 due to write too good, the direct pick down.

Supplementary Summary:

After questioning, online lookup and testing, it is found that the number of bits in memory is actually related to the number of digits in the operating system and the compiler (the number of bits supported by different compilers) . A specific data type is a byte count. The compiler allocates the memory size based on the number of operating system bits. The exact answer can be obtained by using sizeof (int) when you want to know the exact number of bits of memory in use.


Second, reprinted from: https://zhidao.baidu.com/question/128406170.html

Int16 Maximum minimum range of values. The Int16 is between 32768 and +32767. In C-Language programming languages (C, C + +, C #, Java, etc.), is an integer data type definition of identifiers.   For example: int i;.   Commonly used SCM compiler, such as Keil, 51 types of single-chip computer in the C language, int represents 2 bytes (16 bits), and in the C language of 32-bit RAM processors, int is for 4-byte (32-bit) pic MCU's PICC 8-digit series MCU in C language int represents 16 bits.   and many PC-side software compilers will be based on the operating system or processor (such as 64-bit XP) to define int as 8 bytes (64 bits) so the people who program on multi-platform need to be aware of when they use it.   If you want to define a 16-digit number, you can use the short (shorter, short integer type) definition. int can also be used for constants (let).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.