Trusted answers to developer questions

What is the auto keyword in C++?

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

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;
}

RELATED TAGS

auto
c++
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?