Data Types
Auto Type
The auto keyword lets C++ infer a variable type from its initializer.
Auto Type
auto_type.cpp
#include <iostream>
#include <string>
int main() {
int count = ;
auto doubled = count * 2;
auto label = std::string("items");
std::cout << "count=" << count << std::endl;
std::cout << "doubled=" << doubled << std::endl;
std::cout << "label=" << label << std::endl;
return 0;
}
#include <iostream>
#include <string>
int main() {
int count = ;
auto doubled = count * 2;
auto label = std::string("items");
std::cout << "count=" << count << std::endl;
std::cout << "doubled=" << doubled << std::endl;
std::cout << "label=" << label << std::endl;
return 0;
}
#include <iostream>
#include <string>
int main() {
int count = ;
auto doubled = count * 2;
auto label = std::string("items");
std::cout << "count=" << count << std::endl;
std::cout << "doubled=" << doubled << std::endl;
std::cout << "label=" << label << std::endl;
return 0;
}
auto
`auto` asks the compiler to choose the type from the value on the right side of `=`.