Conversation started Apr 16, 2020 at 5:11.
Apr 16, 2020 05:11
if my computer is 32 bits then 2^32-1 is the largest bit and 2^32 is the number of bits?
so size_t is of size 2^32-1 or 2^32?
unsigned integers i mean
Whenever you find yourself thinking about problems like this choose a simple example to start with. For example consider one bit. The only possible numbers are 0 and 1. So there are 2^1 possible numbers and the largest possible number is 2^1 - 1.
Or with two bits the possible numbers are 0, 1, 2 and 3. So there are 2^2 possible numbers and the largest possible number is 2^2 - 1.
yeah
So on a 32 bit system there are 2^32 possible numbers and the largest possible number is 2^32 - 1.
Apr 16, 2020 05:16
so size_t is 2^32-1 right?
That's the largest possible value of a size_t.
sizeof(size_t) = 4 i.e. a size_t is 4 bytes or 32 bits.
ah so size_t is 0 t 2^32-1?
both included
@Aladdin Yes
if it was 64 then 0 to 2^64-1
and size will be 8 bytes
ok got it
Apr 16, 2020 05:23
so for a 64 bit computer
if i do size_t 4
it will represent 4 in 64 bits
Strictly speaking it's whether the program is 32 or 64 bits.
All computers are 64 bit these days, even your phone.
But 64 bit computers will run 32 bit programs and by default Visual Studio compiles C to 32 bit.
So your program is 32 bit even though it's running on a 64 bit computer. There is an option somewhere in VS to tell it to use 64 bit instead. I can try and find it if you want ...
no it's ok
i don't need it now anyways
In most cases it makes no difference whether the program is compiled for 32 or 64 bit. It runs the same way in both cases.
 
Conversation ended Apr 16, 2020 at 5:32.