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;
}
Copyright ©2024 Educative, Inc. All rights reserved