In C++, the auto keyword lets you define a variable with the type based on its initialization expression. something similar to var keyword in C#, though auto has much higher scope.
See the program you mentioned modified with to see the correct usage of auto.
#include <stdio.h>
int main()
{
int a = 1;
printf("Value of 'a' is %d\n", a);
{
//correct declaration of auto variable.
auto a = 2;
printf("Value of 'a' is %d\n", a);
}
printf("Value of 'a' is %d\n", a);
{
int a = 3;
printf("Value of 'a' is %d\n", a);
}
printf("Value of 'a' is %d", a);
return 0;
}
The auto can be used even as a function return type. see the following example.
#include <iostream>
// Create a function
auto myFunction() {
return 3 * 2;
}
int main() {
printf("Value of 'a' is %d", myFunction());
return 0;
}
I recommend you to refer the following article for further details.
https://learn.microsoft.com/en-us/cpp/cpp/auto-cpp?view=msvc-170
Hope this helps