typeid operator in C++ with Examples Last Updated : 03 Sep, 2021 Comments Improve Suggest changes Like Article Like Report typeid is an operator in C++. It is used where the dynamic type or runtime type information of an object is needed.It is included in the <typeinfo> library. Hence inorder to use typeid, this library should be included in the program.The typeid expression is an lvalue expression. Syntax: typeid(type); OR typeid(expression); Parameters: typeid operator accepts a parameter, based on the syntax used in the program: type: This parameter is passed when the runtime type information of a variable or an object is needed. In this, there is no evaluation that needs to be done inside type and simply the type information is to be known.expression: This parameter is passed when the runtime type information of an expression is needed. In this, the expression is first evaluated. Then the type information of the final result is then provided. Return value: This operator provides the runtime type information of the specified parameter and hence that type information is returned, as a reference to an object of class type_info.Usage: typeid() operator is used in different way according to the operand type. When operand is a variable or an object. CPP // C++ program to show the use of typeid operator #include <iostream> #include <typeinfo> using namespace std; int main() { int i, j; char c; // Get the type info using typeid operator const type_info& ti1 = typeid(i); const type_info& ti2 = typeid(j); const type_info& ti3 = typeid(c); // Check if both types are same if (ti1 == ti2) cout << "i and j are of" << " similar type" << endl; else cout << "i and j are of" << " different type" << endl; // Check if both types are same if (ti2 == ti3) cout << "j and c are of" << " similar type" << endl; else cout << "j and c are of" << " different type" << endl; return 0; } Outputi and j are of similar type j and c are of different typeWhen operand is an expression. CPP // C++ program to show the use of typeid operator #include <iostream> #include <typeinfo> using namespace std; int main() { int i = 5; float j = 1.0; char c = 'a'; // Get the type info using typeid operator const type_info& ti1 = typeid(i * j); const type_info& ti2 = typeid(i * c); const type_info& ti3 = typeid(c); // Print the types cout << "ti1 is of type " << ti1.name() << endl; cout << "ti2 is of type " << ti2.name() << endl; cout << "ti3 is of type " << ti3.name() << endl; return 0; } Output: ti1 is of type f ti2 is of type i ti3 is of type c Comment More infoAdvertise with us Next Article typeid operator in C++ with Examples I iamyateesh Follow Improve Article Tags : Algorithms C++ DSA cpp-data-types cpp-operator +1 More Practice Tags : CPPAlgorithmscpp-operator Similar Reads Map of Tuples in C++ with Examples What is a tuple? A tuple in C++ is an object that has the ability to group a number of elements. The elements can be of the same type as well as different data types. The order in which tuple elements are initialized can be accessed in the same order. Functions associated with a tuple: 1. make_tuple 4 min read ios operator() function in C++ with Examples The operator() method of ios class in C++ is used to any error flag of this stream is set. This includes the failbit or the badbit. Syntax: operator void*() const; Parameters: This method does not accept any parameter. Return Value: This method returns a null pointer if any error bit is set of this 1 min read ios operator() function in C++11 with Examples The operator() method of ios class in C++11 is used to any error flag of this stream is set. This includes the failbit or the badbit. Syntax: explicit operator bool() const; Parameters: This method does not accept any parameter. Return Value: This method returns false if any error bit is set of this 1 min read How to Overload == Operator in C++? A class in C++ is the building block that leads to Object-Oriented programming. Class is a user-defined data type, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class. The overloading of operators is a polymorphism that occurs a 2 min read Vector Operator = in C++ STL In C++, the vector operator = is used to assign the contents of one vector to another. It allows you to copy elements from one vector to another or initialize a vector with another vector's contents.Letâs take a look at a simple code example:C++#include <bits/stdc++.h> using namespace std; int 3 min read Like