C++ data types are confusing.
10 minutes ago, RTXboy123 said:So you mean that for int, the least amount of memory is 16 bits, but it can scale up to 32 bits?
For int, you know that it can hold at least -32,767 to 32,767, so it has at least 16 bit. No other promises are made. It could be 32 bit, or even 64 bit, depending on the platform your program is executing on, but you shouldn't rely on that. It does not "scale up" or change dynamically, the size is fixed, but can vary by platform (e.g. Linux vs Windows)
If you need to store a 32 bit value, you should use long, because you know it will always be at least 32 bit in size, no matter the underlying platform. Likewise long long will always be at least 64 bit in size.
If your program only ever runs on Windows and you know that int is 32 bit on that platform, while long is 64 bit, you can get away with using them that way (e.g. if you absolutely don't want to "waste" memory space). You just need to be aware that your program isn't portable, because those assumptions might fail elsewhere.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now