
- 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
What is type deduction 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.
- Related Articles
- What is type inference in C++?
- What is Type casting in C#?
- What is Type conversion in C#?
- What is Type safe in C#?
- What is type conversion in java?
- What is Type Assertion in TypeScript?
- What is Type Conversion?
- What is BLOB data type in MySQL?
- What is TEXT data type in MySQL?
- What is covariant return type in Java?
- What is JavaScript type coercion?
- What is Static Type Checking?
- What is Dynamic Type Checking?
- What is the difference between type conversion and type casting in C#?
- What type of reflector is used in a box-type solar cooker?

Advertisements