Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What is the use of short in c language%?
What is the use of short in c language%?
Short, like int, is an internal data type of C or C++. Used to represent a signed integer.

The difference is that they occupy different space in memory. Short usually accounts for half of int, and some implementations are the same as int, but not larger than int.

The range of integers that can be represented is different with different memory space.

As for what scope it can represent, this question is related to the architecture and compilation environment. You can try the following c++ program.

# include & ltiostream & gt

Use namespace std

int main()

{

cout & lt& ltsizeof(short)& lt; & ltendl

cout & lt& ltsizeof(int)& lt; & ltendl

cout & lt& ltsizeof(long)& lt; & ltendl

cout & lt& ltsizeof(_ _ int 64)& lt; & ltendl

}

On my computer VC8, the result of compiling and running is

2

four

four

eight

In other words, short takes 2 bytes, int takes 4 bytes like long, and __int64 takes 8 bytes. The more bytes, the larger the range of numbers that can be represented!

For example, a 2-byte signed integer, that is, 16 bits, ranges from -2 15 to 2 16- 1, and 2 n represents the n power of 2.