int
is the default integer type in C. It is a signed integer type that can represent whole numbers. The size of int
is implementation-defined, which means that it can vary depending on the platform and compiler you are using. However, it is typically 4 bytes on most modern systems.
The range of values for a standard int
on a 32-bit system is from -2147483648 to 2147483647. This is because a 32-bit int
uses 32 bits to represent signed integers, which allows it to store values in the range of -2^31 to 2^31-1. The maximum value is one less than the minimum value because 0 is included in the range of positive values.
The short
keyword is used to define a short integer type in C. A short
integer typically uses fewer bits than a standard int
to represent values, which allows it to store a smaller range of values. The exact number of bits used by a short
integer can vary depending on the system and compiler, but it is typically less than the 32 bits used by a standard int
.
The typical range of values for a short int
on a 32-bit system is from -32768 to 32767. This is because a short int
typically uses 16 bits to represent signed integers, which allows it to store values in the range of -2^15 to 2^15-1. The maximum value is one less than the minimum value because 0 is included in the range of positive values. The exact range of values for a short int
can vary depending on the system and compiler, but this is the typical range for a 16-bit short int
on a 32-bit system.
To declare an unsigned integer in C, you use the unsigned
keyword before the integer type. For example, to declare an unsigned integer variable named x
, you would write:
unsigned int x;
unsigned int
on a 32-bit system?0 to 4,294,967,295
long
-2,147,483,648 to 2,147,483,647 (same as int on a 32-bit system)
long long
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long long
unsigned long long
int on a 64-bit system?0 to 18,446,744,073,709,551,615
int
in C?%d
or %i
unsigned int
in C?%u
long int
in C?%ld
long long int
in C?%lld
unsigned long long int
in C?%llu
Using the const
keyword, e.g., const int x = 10;
sizeof
operator in relation to integers?It determines the number of bytes allocated for a data type or variable, e.g., sizeof(int)
int x = 5;