
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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; }
Output
In the above program, it will automatically get the type std:: vector<int>:: iterator.
- Related Articles
- What is type inference in C++?
- Type Inference in C++ (auto and decltype)
- Type Inference in Lambda expression in Java?
- Local Variable Type Inference or LVTI in Java 10
- Role of Statistical Inference in Psychology
- Consumer Inference: Meaning and Types
- The Predator-Prey Inference System
- Rules Of Inference for Predicate Calculus
- Inference Theory of the Predicate Calculus
- Inference Theory of the Predicate Logic
- Features of Domain-Specific Inference Systems
- Explain the inference rules for functional dependencies in DBMS
- Value Type vs Reference Type in C#
- Theory of Inference for the Statement Calculus
- Buffer Type in C#

Advertisements