//When using auto variables, the data type is decided in initialisation
#include <iostream>
using namespace std;
int main() {
auto IntegerVar=25; //creates integer type variable
auto FloatVar=26.77; //creates float type variable
auto StringVar="Hello"; //creates string type variable
auto CharVar="C"; //creates char type variable
cout<<"CREATING VARIABLES USING AUTO DATA TYPE
";
cout<<"Integer: "<<IntegerVar<<endl;
cout<<"Float: "<<FloatVar<<endl;
cout<<"String: "<<StringVar<<endl;
cout<<"Char: "<<CharVar;
cout<<"
";
return 0;
}
int foo = 0;
auto bar = foo; // the same as: int bar = foo;
// type of bar is the type of the value used to initialize it
#include<iostream>
#incllude<vector>
using namespace std;
int main() {
vector<int> vec(10); // Auto deduce type to be iterator of a vector of ints.
for(auto it = vec.begin(); it != vec.end(); vec ++)
{
cin >> *it;
}
return 0;
}
auto n=1;
// this will make the type int, and you can't change trough the program;
cout << n;
// OR
auto n="how you doin'";
cout << n;
Code Example |
---|
Cpp :: c++ program to convert character to ascii |
Cpp :: stl c++ |
Cpp :: array of Methods c++ |
Cpp :: array of struct in c++ |
Cpp :: check even or odd c++ |
Cpp :: difference between --a and a-- c++ |
Cpp :: two elements with difference K in c++ |
Cpp :: toupper c++ |
Cpp :: class operator overloading c++ |
Cpp :: how to initialize a queue in c |
Cpp :: lambda function in c++ |
Cpp :: lower bound and upper bound in c++ |
Cpp :: cpp execute command |
Cpp :: qt make widget ignore mouse events |
Cpp :: trie code cpp |
Cpp :: clear previous terminal output c++ |
Cpp :: constrain function in arduino |
Cpp :: why use python |
Cpp :: c++ comment out multiple lines |
Cpp :: c++ hash map key count |
Cpp :: Array declaration by specifying the size in C++ |
Cpp :: c++ queue |
Cpp :: hide window c++ |
Cpp :: remove element from c++ |
Cpp :: c++ pointers and arrays |
Cpp :: c++ switch case |
Cpp :: unique element in array in c |
Cpp :: queue |
Cpp :: c++ add everything in a vector |
Cpp :: what is a .h file in c++ |