Is an int in C# 32 bits?

c#

Solution

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.

Problem

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?

Original source

Related problems