What is the auto keyword in C++?

The auto keyword enables a variable’s declaration without specification of its data type.

#include <iostream>
using namespace std;
int main() {
auto unknown_variable = "eleven";
cout<< unknown_variable;
}

The auto keyword is particularly useful with function calls, especially in cases where​ the function return type is not certain.

#include <iostream>
using namespace std;
double num_generator(){
return 401.8;
}
int main() {
auto unknown_variable = num_generator();
cout<< unknown_variable;
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved