From the course: C++ Best Practices for Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

size_t and auto

size_t and auto - C++ Tutorial

From the course: C++ Best Practices for Developers

Start my 1-month free trial

size_t and auto

- [Instructor] Size_t is a basic unsigned integer. It's size depends on the system. It can store the maximum size of a theoretically possible object of any type, including a ray. Using size_t can improve your code's portability and efficiency. Most index containers in the STL use size type, which is another name for size_t. Since C++14, you can use auto as a return type, but all returns should have the same type. We have a code sample to illustrate the points. So, let's switch over to Visual Studio Code. And let's start off that we have this function called, sumDown, and it is a recursive add function. You give it a number like 10, and it'll keep going from 10 all the way down to zero, and add all the numbers up along the way. Now, notice that we have a type auto here and we have a return type of zero for an integer. And also, this is going to be an integer of what's getting added here. And that's using auto as a return type. Now here, we're using size_t in a various different ways…

Contents