why we have an int type when we already have short and long ints
because int means either short or long.

why we have an int type when we already have short and long ints
because int means either short or long.

as i know you choose the best data type according to the range it provides and save memmory as possible
example:int takes in memmory two bytes and its rang from -32000to 32000 but long takes four byts and its range is wider

because int means either short or long.

Or maybe it doesn't. Maybe int, short, and long all have different ranges. Gee. I guess there's a reason, then.

Or maybe it doesn't. Maybe int, short, and long all have different ranges. Gee. I guess there's a reason, then.

please some guru provide a correct reason on this because
it is not as simple as it looks

please some guru provide a correct reason on this because
it is not as simple as it looks

There is no one correct reason. All the reasons mentioned in this thread are correct. There is another integer type -- char which is a one byte integer. And of course there is the 64-byte integer known as long long, or sometimes __int64.

> why we have an int type when we already have short and long ints
You got it the wrong way round.
C evolved from B and BCPL, where the only data type was "the machine word". This became the int type in C. The short and long got added later (but still available in K&R C).

In archaic C, the default data type was int, so you could just say things like

main ( argc, argv )
char **argv;
{
}

where argc was an int, and the return result of main was also int.

When the ANSI/ISO standards came along, then
short int - at least 16 bits
long int - at least 32 bits
int - at least 16 bits, but ideally should reflect the architecture of the machine.

> because int means either short or long.
No it doesn't. Your experience to date only suggests that int is either short or long.
The standards only specify MINIMUM ranges for each data type. Beyond that, the compiler implementer has quite a lot of freedom to choose.
On some DSP chips, short, int and long are all the same (32 bits).
On common Intel hardware, short and long are different, and int is the same as one of them.
When 64 bit hardware becomes common, short is likely to remain at 16 bits, int at 32 bits and long may move out to 64 bits.

> why we have an int type when we already have short and long ints
You got it the wrong way round.
C evolved from B and BCPL, where the only data type was "the machine word". This became the int type in C. The short and long got added later (but still available in K&R C).

In archaic C, the default data type was int, so you could just say things like

main ( argc, argv )
char **argv;
{
}

where argc was an int, and the return result of main was also int.

When the ANSI/ISO standards came along, then
short int - at least 16 bits
long int - at least 32 bits
int - at least 16 bits, but ideally should reflect the architecture of the machine.

> because int means either short or long.
No it doesn't. Your experience to date only suggests that int is either short or long.
The standards only specify MINIMUM ranges for each data type. Beyond that, the compiler implementer has quite a lot of freedom to choose.
On some DSP chips, short, int and long are all the same (32 bits).
On common Intel hardware, short and long are different, and int is the same as one of them.
When 64 bit hardware becomes common, short is likely to remain at 16 bits, int at 32 bits and long may move out to 64 bits.

Can you Please Specify How to run the program using GCC ( on linux ) by using the Standard. ( K&R , ANCI ,ISO )

What, and deprive you of an opportunity to read the manual?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.