auto in c++ code example
Example 1: pionter in c++
#include <iostream>
using namespace std;
int main(){
//Pointer declaration
int *p, var=101;
//Assignment
p = &var;
cout<<"Address of var: "<<&var<<endl;
cout<<"Address of var: "<<p<<endl;
cout<<"Address of p: "<<&p<<endl;
cout<<"Value of var: "<<*p;
return 0;
}
Example 2: floor() in c++
floor(x):This function in C++ returns the smallest possible integer value which is smaller
than or equal to the given argument.
Input : 2.5 ,-2.1 ,2.9
Output : 2 ,-3, 2
Example 3: auto in c++
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
Example 4: auto in cpp
#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;
}