sizeof int ,

hello
i want to know that if check the size of int in turbo c++ then its show 2 bytes and if check the size of int in code block then it show the 4 bytes
and how the size of int depend on the system if i have a 64 bit system ?
The size of int depends on the data model being employed by the compiler: http://en.cppreference.com/w/cpp/language/types#Data_models

you mean to say that its basically depend on compiler only
No, I phrased it like that to include the possibility that a compiler could use different data models if it was told to.
what is LP, ILP,LLP ?
Good question... I've always just assumed that it stood for "integer, long, pointer". But now that I look at it that doesn't necessarily make sense. I will get back to you on that one.
I suspect it does refer to integer, long and pointer. Apparently, only the largest values are listed, so LP32 means long and pointer are 32 bits, but integer is shorter. The one that might throw someone off is the LLP64. In this case, I guess that the long long type and the pointer are 64 bits, but integer and long are shorter.
ok i understand
but can any one tell that it would happen only with int data type or this would happen with float or char?
- sizeof(char) is always 1 byte, whichever platform you use.
- I have never seen sizeof(float) being different from 4 bytes because floating point numbers are stored in IEEE 754 32-bit floating point format. I would however not count on it though that some platforms/compilers might behave differently.

so thats mean only int is takes diff bytes in diff system ?
ALL types BUT char have a possibly variable size.
Use uint32_t, uint16_t, int32_t, int16_t, ... (They must be included from a file, I do not remember which one it was).
Last edited on
you are saying that all type takes diff bytes in diff system but i read from many book they told that changing in bytes happen only with int not for float and char
I repeat: ONLY char has a guaranteed size.
Change your book, change your compiler (Turbo C++? In 2014?)
Size of integers is not related to 32/64bits, anyways.
Last edited on
ok
what about float and double they change with system ?
Last edited on
Read: http://en.wikipedia.org/wiki/C_data_types

Personally I only count on these 2 things:
- char is always 1 byte
- c99 fixed length types have indeed a fixed length.

"what about float and double they change with system ?"
Wouldn't count on it. Why would you want to take the risk? Just use sizeof
Once again: ONLY chars do not change.
Any other type may have any other size.
This is what you can rely on:
char <= short <= int <= long
char <= float <= double
Last edited on
Topic archived. No new replies allowed.