Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the variable types and memory size of C language

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to understand the variable type and memory size of C language". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn how to understand the variable type and memory size of C language.

Type storage size range c input and output format specific range char1byte (8 bit)-2 ^ 7 ~ 2 ^ 7-1%c-128 to 127unsigned char1byte (8 bit) 0 ~ 2 ^ 8-1%c0 to 255signed char1byte (8 bit)-2 ^ 7 ~ 2 ^ 7-1%c-128 to 127short2byte (16 bit)-2 ^ 15 ~ 2 ^ 15-1%d-32768 to 32767unsigned short2byte (16 bit) 0 ~ 2 ^ 16-1%u0 to 65535int4byte (32 bit)-231 ^ 2 ^ 31-1%d-2147483648 to 2147483647unsigned int4byte (32 bit) 0 ~ 2 ^ 32-1%u0 to 4294967295long4byte (32 bit)-2 ^ 31 ~ 2 ^ 31-1%ld-2147483648 to 2147483647unsigned long4byte (32 bit) 0 ~ 2 ^ 32-1%lu0 to 4294967295long long8byte (64 bit) 2 ^ 63 ~ 2 ^ 63-1%lld-9223372036854 775808 to 9223372036854775807unsigned long long8byte (64 bit) 0 ~ 2 ^ 64-1%llu0 to 18446744073709551615 float4 byte% lf 8byte-input % f-long double10byte- for output% Lf- for both input and output

In addition, there is a void type:

The void type specifies that no values are available. It is commonly used in the following three situations:

Description:

Different compilers may not have different data lengths for some types, which are generally the above rules, just understand it.

The compiler can choose the appropriate size according to its own hardware, but it needs to meet the constraints: the short and int types are at least 16 bits, the long type is at least 32 bits, and the length of the int type cannot exceed the int type, and the int type cannot exceed the long type. This means that the length of each type of variable is determined by the compiler, while the current mainstream compilers generally have 4 bytes in 32-bit machines and 64-bit machines. That is to say,

Note:

(1) int and unsigned int may only occupy two bytes

(2) long may occupy 8 bytes

(3) in addition to long long and unsigned long long, there are _ _ int64 and unsigned _ _ int64, whose input and output format can be in% I64d. The two have the same range, but different compilers have different compatibility. For more information, please refer to the test results of others:

The difference between _ _ int64 and long long

Thank you for your reading, the above is the content of "how to understand the variable type and memory size of C language". After the study of this article, I believe you have a deeper understanding of how to understand the variable type and memory size of C language, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report