how does long and long long differ? The machine I am using has core 2 duo processor. It shows the same size (8 bytes) for both of them.

Was short type ever was 1 byte and changed to 2 bytes later on? Was long and int ever was 4 byte and 2 bytes respectively?

How to specify long long int and long long double (does it exist?) in printf and scanf?

Which data types among char, int, long, float, double has the same size different platforms?

Edited 6 Years Ago by johndoe444: n/a

The size of data types is mostly compiler dependent. See limits.h for sizes and maximum values.

>>Was short type ever was 1 byte and changed to 2 bytes later on?
Not that I know of, but could have been depending on the compiler.

>>How to specify long long int and long long double (does it exist?) in printf and scanf?

long == "%ld"
long long == "%lld"
double = "%lf"
long double = "%llf"

AFAIK there is no such thing as long long double, but I suppose there could be on some 128-bit machines.

>>Which data types among char, int, long, float, double has the same size different platforms?
All of them. C/C++ standards do not dictate the size of variables (except char is guaranteed to be 1). only that char <= short <= int <= long <= float <= double. So I suppose they could all the the same size on some platform.

Edited 6 Years Ago by Ancient Dragon: n/a

>how does long and long long differ?
long was originally intended to be 32 bits and long long to be 64. These are the minimum limits though, so as the need for longer types grows, they could grow to accommodate it.

>Was short type ever was 1 byte and changed to 2 bytes later on?
No, short has always been at least 16 bits.

>Was long and int ever was 4 byte and 2 bytes respectively?
The minimum for long is 32 bits, and the minimum for int is (surprisingly to some) 16 bits. So you could say that long is at least 4 bytes and int is at least 2 bytes presently (assuming an 8-bit char type), but could be more depending on the implementation.

>double = "%lf"
This is for scanf, by the way. printf performs default promotions such that everything is double, and thus the unadorned floating-point specifiers are sufficient. Note that "%lf" is undefined in C89 and a the length modifier is ignored in C99.

>long double = "%llf"
That would certainly be consistent with long long, but sadly, "%llf" is undefined behavior. long double uses an upper case L: "%Lf".

>how does long and long long differ?
long was originally intended to be 32 bits and long long to be 64. These are the minimum limits though, so as the need for longer types grows, they could grow to accommodate it.

>Was short type ever was 1 byte and changed to 2 bytes later on?
No, short has always been at least 16 bits.

>Was long and int ever was 4 byte and 2 bytes respectively?
The minimum for long is 32 bits, and the minimum for int is (surprisingly to some) 16 bits. So you could say that long is at least 4 bytes and int is at least 2 bytes presently (assuming an 8-bit char type), but could be more depending on the implementation.

According to this article you are wrong (gasp!), and I seem to recall you saying the same several times in the past.

The size and range of any data type is compiler and architecture dependent.

Edited 6 Years Ago by Ancient Dragon: n/a

>According to this article you are wrong
On the contrary, I'm more correct than the article. :) The standard places hard minimum limits. Implementations are free to exceed those limits, but going below them would be non-conforming. The article you linked to isn't wrong per se, but it does omit the part about minimum requirements, which could be misleading.

Comments
awesome
This article has been dead for over six months. Start a new discussion instead.