Quick question, What is size_t?

I have seen size_t a few times and have done a little bit of research but still dont understand what it is. So basically I want to know what it is and why should i ever use it?
Thats all gibberish to me, i need a simplified explanation please.
Last edited on
try reading it again, it says its an unsigned int that the listed functions return.
So size_t is just an unsigned int? so i could do unsigned int instead of size_t?
If it's defined as such it should work fine, but why not use size_t if it's setup and is what the functions expect?
No i am going to use size_t i was just wondering what it was about. so if size_t is for an unsigned int, is there one for a signed int? also when would i ever use size_t?
Some of this may help...


and I can't see any use for a negative size, but I could be wrong.

Use it for functions that expect a variable representing a size, the functions listed by TheIdeasMan use it, and you can use it if you make a function requiring a size parameter.
AFAIK, it is only for C, you shouldn't need it for C++. If there are any C++ functions that use this then you should be aware of it.

Ch1156 wrote:
so i could do unsigned int instead of size_t?

as an unsigned integral type.

That doesn't mean that it is an int, necessarily - it could long, or long long .

So I agree with Moooce

size_t is used in a number of places in the C++ standard library.

This is what the standard says about size_t.
The type size_t is an implementation-defined unsigned integer type that is large enough to contain the size in bytes of any object.

Topic archived. No new replies allowed.