C++ examples for Data Type:auto
You use the auto keyword to let the compiler deduce the type.
#include <limits> #include <iostream> int main()/* ww w.ja va 2 s.c o m*/ { auto m = 10; // m is type int auto n = 200UL; // n is type unsigned long auto pi = 3.14159; // pi is type double std::cout << m; std::cout << n; std::cout << pi; }
You can use functional notation with auto for the initial value:
#include <limits> #include <iostream> int main()/*from w w w. j av a 2 s. c om*/ { auto pi(3.14159); // pi is type double std::cout << pi; }