Search code examples
c++auto

What is the simplest example using auto in C++?


I try to understand how auto is used in C++. For me the best way to understand something is to see an example. However, the examples that I saw are not so simple. For example here is "Meaning of C++0x auto keyword, by example?". To understand this example I need to know what are "templates", "pointers", "malloc" and so on.

Can anybody, please, give an minimalistic example using auto so one can easy understand what it is used for?


Solution

  • int a = 10;
    int b = 20;
    
    auto c = a+b; // c will be int