How many bytes is uint32

42project.net

Before a variable can be used in the program, it must be declared. Data types are used to assign a type to a variable. It is important to know the size of the different data types in order to prevent variable overflows.

The value range of a data type can be calculated using the following formula:

Integer data types:

C typesstdint.h
Types
BitssignRange of values
charuint8_t8Unsigned
unsigned
0 to
255
signed charint8_t8Signed
with sign
-128 to
127
unsigned shortuint16_t16Unsigned
unsigned
0 to
65,535
shortint16_t16Signed
with sign
-32768 to
32767
unsigned int

(2 or 4 bytes)

uint32_t32Unsigned
unsigned
0 to
4294967295
int (2 or 4 bytes)int32_t32Signed
with sign
-2147483648 to
2147483647
unsigned
long long
uint64_t64Unsigned
unsigned
0 to
18446744073709551615
long longint64_t64Signed
with sign
-9223372036854775808 to
9223372036854775807

Depending on the platform, an int / unsigned int can be 2 or 4 bytes in size. To get the exact size of a type or variable on a particular platform, the sizeof Operator can be used. The expression sizeof (type) supplies the memory size of the object or type in bytes. Below is an example of the size of the int Type on every machine.

Floating point types

The following table shows the details of standard floating point types with memory sizes and value ranges and their precision.

C typesBitsRanges of valuesaccuracy
float321.2E-38 to 3.4E + 386 decimal places
double642.3E-308 to 1.7E + 30815 decimal places
long double803.4E-4932 to 1.1E + 493219 decimal places

The header file float.h defines macros with which these data types can be used, as well as querying information about the binary representation of real numbers. The following example prints the space occupied by a floating point type and its range of values.

The void data type

The void type indicates that no value is available.