C auto Keyword
Example
Create a local variable with the auto keyword:
auto int myNum = 15; // Same as: int myNum = 15;
printf("%d", myNum);
Definition and Usage
The auto keyword declares a local variable. The variable is created when its block (the code between { and }) starts, and it is removed when the block ends.
All local variables work like this by default, so auto int myNum = 15; means the same as int myNum = 15;. That is why the keyword is rarely written.
Note: In C++ (and in C23), auto can also mean something else. If you write it without a type, like auto x = 15;, the compiler works out the type from the value.
Related Pages
Read more about auto and other storage classes in our C Storage Classes Tutorial.