So in my exam in the class I was supposed to declare X as a short unsigned. I declared it short unsigned int X. Is this way still OK and correct? Thank you
Asked
Active
Viewed 334 times
1
-
It goes for all built-in integral types, check this [answer](https://stackoverflow.com/a/7176690/14624729). – rawrex Jun 24 '21 at 13:47
-
You can declare it as `unsigned short X` – FaisalM Jun 24 '21 at 13:48
-
1These are all the same, which to use is a matter of *style*: `short unsigned`, `unsigned short`, `int short unsigned`, `short int unsigned`, `short unsigned int`, `int unsigned short`, `unsigned int short`, `unsigned short int` – Eljay Jun 24 '21 at 13:55
-
Reminder: most of the integer types are based on range, not bitwidth. For example, I could have a 32-bit processor that uses a 32-bit value for `char` or `short`, and still be compatible with the language. – Thomas Matthews Jun 24 '21 at 16:41
1 Answers
3
Yes, short unsigned int
and short unsigned
are exactly the same type.
Personally I prefer unsigned short
for readability.
See for yourself by testing
std::is_same<short unsigned int, short unsigned>::value

Bathsheba
- 231,907
- 34
- 361
- 483