I have just heard that the size of an int is machine dependant. I have always thought that the size of an int is 32 bits. Can someone explain this conundrum?
-
1`int` is a synonym for `System.Int32`, which is always exactly 32-bits. `long` / `System.Int64` is C#'s 64-bit integer data type. – JosephHirn Feb 15 '13 at 17:38
4 Answers
In C#, the int
type is always an Int32
, and is always 32 bits.
Some other languages have different rules, and int
can be machine dependent. In certain languages, int
is defined as having a minimum size, but a machine/implementation specific size at least that large. For example, in C++, the int datatype is not necessarily 32 bits. From fundimental data types:
the general specification is that int has the natural size suggested by the system architecture (one "word") and the four integer types char, short, int and long must each one be at least as large as the one preceding it, with char being always one byte in size.
However, .NET standardized this, so the types are actually specified as Int32
, Int64
, etc. In C#, int
is an alias for System.Int32
, and will always be 32 bits. This is guaranteed by section 4.1.5 Integral Types
within the C# Language Specification, which states:
The int type represents signed 32-bit integers with values between –2147483648 and 2147483647.

- 554,122
- 78
- 1,158
- 1,373
-
1although if you specifically want a 64 bit integer, you can use `long` or `Int64` – DiskJunky Feb 15 '13 at 17:39
-
1
-
1true but it was implicit in the question that there was abiguity between 32 bit and 64 bit integers, presumably on 64 bit processors :-) Although, possibly 16 bit processors too if compiling for device but we're going *way* off topic at this point. Disregard! :-) – DiskJunky Feb 15 '13 at 17:42
MSDN states that int
is 32 bits. Was the person talking about C++ perhaps?
In C++
size of integral types in bytes is unspecified by the standard
-
-
1@SachinKainth As you can see from the answer in my edit, it is unspecified – Karthik T Feb 15 '13 at 17:41
From the C# Language Specifications:
The
int
type represents signed 32-bit integers with values between –2147483648 and 2147483647.

- 6,192
- 1
- 30
- 34
int
is an alias of System.Int32
. You also can use System.Int16
, System.Int64
and BigInteger
.

- 2,459
- 6
- 29
- 53