I recently came across this keyword size_t,I read about it in the official C++ documentation but didn't quite able to get my head around it. I don't have much experience or profound knowledge in C++. Can someone kindly explain it to me in simple terms. I would be very grateful to him/her. Looking forward to get your replies.
std::size_t is a type alias for a suitable unsigned integer type, (like unsigned long long,) which is large enough to represent the size of (number of bytes in) the largest array possible.
std::size_t is commonly used for array indexing and loop counting. Programs that use other types, such as unsigned int, for array indexing may fail on, e.g. 64-bit systems when the index exceeds UINT_MAX or if it relies on 32-bit modular arithmetic. http://en.cppreference.com/w/cpp/types/size_t
why is that it's used for array indexing and loop counting??? Is there any sort of benefit that we get out of it or it's just the traditional which asks us to follow ???
Thanks so much. I didn't know that at all. Can you please point further what it means when you said "is a type alias for a suitable unsigned integer type"?? Please provide it with some examples,that would help me to understand it in much better way. And thanks again :)
using my_int_type = long ; // 'my_int_type' is another name for the type 'long'
typedeflong int_type ; // alternative syntax
my_int_type n = 0 ; // type of 'n' is long