I'd like to know how much bytes a
32-bit integer
ASCII character (char in C++?)
Pointer (4 bytes?)
Short
Float
Takes up in Delphi, and if it is generally the same in most languages
Also, do the data types mentioned above have a constant size? I mean are the integers 0, 4, 123 and 32231 all of the same size?
A 32-bit integer is ALWAYS four bytes, because 1 byte = 8 bits.
An Integer
is a signed 32-bit integer, and a Cardinal
is a unsigned 32-bit integer. These thus always occupy four bytes, irrespective of the value they represent. (In fact, it is an extremely important fact that simple types do have fixed widths -- low-level programming really depends on this! It is even a cornerstone part of how computers work.)
Smaller integer types are Smallint
(16-bit signed), Word
(16-bit unsigned) and Byte
(8-bit unsigned). Larger integer types are Int64
(64-bit signed) and UInt64
(64-bit unsigned).
Char
was a 1-byte AnsiChar
prior to Delphi 2009; now it is a 2-byte WideChar
.
Pointer
is always 4 bytes, because Delphi currently creates 32-bit applications only. When it supports 64-bit applications, Pointer
will become 8 bytes.
There are three common floating-point types in Delphi. These are Single
, Double
(=Real
), and Extended
. These occupy 4, 8, and 10 bytes, respectively.
To investigate the size of a given type, e.g. Short
, simply try
ShowMessage(IntToStr(SizeOf(Short)))
Reference:
In C/C++, SizeOf(Char) = 1 byte as required by C/C++ standard.
In Delphi, SizeOf(Char) is version dependent (1 byte for non-Unicode versions, 2 bytes for Unicode versions), so Char in Delphi is more like TChar in C++.
It may be different for different machines, so you can use the following code to determine the size of integer(for examle):cout << "Integer size:" << sizeof(int);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With