C++ auto keyword to let the compiler deduce the type.

Description

C++ auto keyword to let the compiler deduce the type.

#include <limits>
#include <iostream>

int main()/*w ww  .  ja  v a  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 ww  .ja v  a2  s  . c  om
{
    auto pi(3.14159);           // pi is type double

    std::cout << pi;
}



PreviousNext

Related