Home > Common Problem > body text

How many bytes does short occupy?

藏色散人
Release: 2023-02-01 11:50:12
Original
24548 people have browsed it

short occupies 2 bytes; short is a type of integer variable family defined in C language; there are three integer types in C language, namely short, int and long; int is called an integer Type, short is called short integer type, and long is called long integer type.

How many bytes does short occupy?

#The operating environment of this tutorial: Windows 10 system, version C11, Dell G3 computer.

How many bytes does short occupy?

Two bytes.

1byte = 8bit One byte occupies 8 binary bits

Windows operating system, 32-bit machine,

char: 1 byte

short: 2 bytes

int: 4 bytes

long: 4 bytes

short in C language It is a kind of defining a family of integer variables. There are three integer types in C language, namely short, int and long. Int is called an integer type, short is called a short integer type, and long is called a long integer type.

In C language, short is a type of integer variable family defined. For example, short i; means defining a short integer variable i.

Length

(1) The number of bytes defined by short is different depending on the program compiler.

(2) The standard defines that short integer variable must not be less than 16 bits, that is, two bytes.

(3) The limits.h in the compiler header folder defines the size that short can represent: SHRT_MIN~SHRT_MAX.

(4) On 32-bit platforms such as windows (32-bit), short is generally 16-bit.

Basic usage

1.C & C short is a data type, ranging from -32768~32767.

2. There are two types:

unsigned short i; i can represent 0~65535

signed (default) short i; i can represent -32768~ 32767

Example

The maximum allowed value of a short int type variable is 32767. If you add 1, what is the result?

#include <stdio.h>
void main() {
       short int a,b;
       a=32767;
       b=a+1;
       printf("a=%d,a+1=%d\n",a,b);
       a=-32768;
       b=a-1;
printf("\na=%d,a-1=%d\n",a,b);
}
Copy after login

What happens in this program is called "overflow", but no error is reported when running. 32767 1 should be equal to 32768, but the running result is -32768.

Recommended learning: "C Video Tutorial"

The above is the detailed content of How many bytes does short occupy?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template