How many bytes would an int contain and how many would a long contain?
Context:
- C++
- 32 bit computer
- Any difference on a 64-bit computer?
How many bytes would an int contain and how many would a long contain?
Context:
It depends on the compiler.
On a 32 bit system, both int and long contain 32 bits. On a 16 bit system, int is 16 bits and long is 32.
There are other combinations!
It depends on your compiler. And your language, for that matter. Try asking a more specific question.
it is platform and compiler specific. do sizeof(int) and sizeof(long) in c or c++.
(I assume you're talking about C/C++)
It's implementation dependant, but this rule should be always valid:
sizeof(short) <= sizeof(int) <= sizeof(long)
That depends greatly on the language you are using.
In C, "int" will always be the word length of the processor. So 32 bits or 4 bytes on a 32 bit architecture.
Hi,
I think it depends on the hardware your using. on 32-bit platforms it is typically 4 bytes for both int and long. in C you can use the sizeof() operator to find out.
int intBytes;
long longBytes;
intBytes= sizeof(int);
longBytes = sizeof(long);
I'm not sure if long becomes 8 bytes on 64-bit architectures or if it stays as 4.
As others have said endlessly, it depends on the compiler you're using (and even the compiler options that you select).
However, in practice, with compilers for many 32-bit machines, you will find:-
The C standard basiucally says that a long can't be shorter than an int which can't be shorter than a short, etc...
For 64-bit CPUs, those often don't change, but you MUST
beware that pointers and ints are frequently not the same size:
sizeof(int) != sizeof(void*)