typeid operator in C++ with Examples Last Updated : 12 Jul, 2025 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 info I iamyateesh Follow Improve Article Tags : C++ cpp-data-types cpp-operator Explore C++ BasicsIntroduction to C++3 min readData Types in C++7 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++5 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++11 min readFile Handling through C++ Classes8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++10 min readPolymorphism in C++5 min readEncapsulation in C++4 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library2 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like