Difference between short age; and short int age;? age is variable.

What's the difference beteween these three statements?
1
2
3
int age;
short int age;
short age;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <iomanip>
#include <limits>

using namespace std;

int main() {

	int age = 0;
	cout << "int: " << sizeof(age) << " min: " << std::numeric_limits<int>::min() << " max: " << numeric_limits<int>::max() << endl;
	short age2 = 0;
	cout << "short: " << sizeof(age2) << " min: " << std::numeric_limits<short>::min() << " max: " << numeric_limits<short>::max() << endl;
	short int age3 = 0;
	cout << "short int: " << sizeof(age3) << " min: " << std::numeric_limits<short int>::min() << " max: " << numeric_limits<short int>::max() << endl;

	return 0;
}


int: 4 min: -2147483648 max: 2147483647
short: 2 min: -32768 max: 32767
short int: 2 min: -32768 max: 32767

short int age; and short age; are exactly the same thing?
Yes.
Thanks a lot!
Using the keyword short is useful when trying to save memory on a lot of values.
@backslashx00 I wouldn't recommend it unless you know for sure the value will never exceed 32767. Plus saving 2 bytes doesn't really help unless you're writing for very very small embedded devices, as which point you're likely using C or ASM
Thanks backslashx00 and Zaita.
Topic archived. No new replies allowed.