
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Type Inference in C++
Type inference or deduction refers to the automatic detection of the data type of an expression in a programming language. It is a feature present in some strongly statically typed languages. In C++, the auto keyword(added in C++ 11) is used for automatic type deduction. For example, you want to create an iterator to iterate over a vector, you can simply use auto for that purpose.
Example
#include<iostream> #include<vector> using namespace std; int main() { vector<int> arr(10); for(auto it = arr.begin(); it != arr.end(); it ++) { cin >> *it; } return 0; }
In the above program, it will automatically get the type std:: vector<int>:: iterator.
Advertisements