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

What are the integers in C++?

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

Share

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

This article will explain in detail what are the integers in C++, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

1, integer

Integers are integers, corresponding to decimals.

Many languages can represent only one integer (e.g. Python), whereas C++ provides several different integers depending on the range of integers.

C++ basic integer has char, short, int, long, in C++ 11 standard, a new long long. Some compilers do not support long long, but support__int64. A separate article explains and supplements this later.

The char type has some special properties and is usually used as a character rather than an integer. In addition, each type comes in both signed and unsigned versions, so there are 10 types in total.

2, short, int, long and long

All four types are integers, the only difference being the range. Depending on the underlying hardware, the range of these four types in C++ is not fixed. There is no way to unify types because of compatibility with different types of systems and hardware.

To avoid inconvenience, C++ provides a flexible standard that ensures a minimum scope for each type.

short at least 16 digits

int is at least as long as short

long is at least 32 bits long and at least as long as int

long long at least 64 bits and at least as long as long

3. Bits and bytes

The basic unit of computer memory is bit. A bit has only two values of 0 and 1, which can be regarded as a switch. There are 256 different combinations of 8 bits, namely. Thus 8 bits can represent 0-255 or-128-127.

Each additional binary bit doubles the range that can be represented. So 16 bits can represent 65536 values, 32 bits can represent 4294672296 values, and 64 bits are larger and can represent approximately. This range is large enough to represent all the stars in the galaxy.

An 8-bit binary bit is a byte, the smallest unit of computer storage. 1024 bytes is called 1KB, 1024 KB is also called 1MB, and 1024MB is 1 GB.

In general, there is a minimum length in the operating system, which is usually determined by the number of CPU bits. Among popular operating systems such as Linux, Windows, and MacOS, int and long are 32 bits, short is 16 bits, and long is 64 bits.

In addition to guessing from the usual situation, C++ also provides some ready-made tools to see. For example, sizeof function, sizeof function can see the number of bytes occupied by variables. This function can accept both the variable type and the variable itself. If the variable type is passed, the result of the calculation is the memory occupied by the variable of that type. Similarly, if the variable itself is passed, it indicates the memory occupied by the variable itself.

Note that parentheses are required when we see that the object is a variable type, and are optional if the variable itself.

cout

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