How to Find the Type of an Object in C++? Last Updated : 28 May, 2024 Comments Improve Suggest changes Like Article Like Report In C++, every variable and object has a type. The type of an object determines the set of values it can have and what operations can be performed on it. It’s often useful to be able to determine the type of an object at runtime, especially when dealing with complex codebases. In this article, we will learn how to find the type of an object in C++. Example: Input:int myInt = 10; double myDouble = 20.0;Output: The type of myInt is: i (int)The Type of myDouble is: d (double)Find the Type of an Object in C++To find the type of an object in C++, we can use the typeid operator provided by the type_info library. The typeid operator returns a reference to a type_info object, which can then be used to get the name of the type. Following is the syntax to use the typeid operator in C++: Syntax of typeidtypeid(object_name).name()where: object_name: is the name of the object whose type we want to determine.name(): The name() method is used to obtain a human-readable representation of the object type.return type: const std::type_info object representing the type of the expression.C++ Program to Find the Type of an ObjectThe below example demonstrates the use of the typeid operator to find the type of a given object in C++. C++ // C++ program to find the type of an object #include <iostream> #include <typeinfo> using namespace std; int main() { // Declare an int and a double int myInt = 10; double myDouble = 20.0; // Use typeid to find the type of myInt cout << "Type of myInt is : " << typeid(myInt).name()<< endl; // Use typeid to find the type of myDouble cout << "Type of myDouble is : "<< typeid(myDouble).name() << endl; return 0; } OutputType of myInt is : i Type of myDouble is : d Time Complexity: O(1) Auxiliary Space: O(1) Note: Here i denotes the object is of type int and d denotes the object is of type double. Comment More infoAdvertise with us Next Article How to Find the Type of an Object in C++? D denzirop9v Follow Improve Article Tags : C++ Programs C++ C-Data Types CPP Examples misc-c +1 More Practice Tags : CPP Similar Reads How to convert a class to another class type in C++? Pre-requisite: Type Conversion in C++, Advanced C++ | Conversion OperatorsThrough class conversion, one can assign data that belongs to a particular class type to an object that belongs to another class type. Example: Let there be two classes 'A' and 'B'. If we want to allocate the details that belo 5 min read How to Use typename Keyword in C++? In C++, the "typename" is a keyword that was introduced to declare a type. It is used for specifying that the identifier that follows is a type rather than a static member variable. In this article, we will learn how to use the typename keyword in C++. C++ typename KeywordThe typename keyword is mai 2 min read C++ Program to Find the Size of int, float, double and char In this article, we will learn to write a C++ program to find the size of int, float, double, and char. It is important to know the size of different data types especially when working with large datasets to optimize memory usage. The size of a variable can be determined using sizeof() operator in C 2 min read <type_traits> Header in C++ The <type_traits> header in C++ is a part of the metaprogramming library introduced in C++ 11. It is a collection of tools to help our code work with different data types. It contains Helper Classes which are standard classes that assist in creating compile-time constants, Type Traits, classes 7 min read boost::type_traits::is_array Template in C++ The std::boost::is_array template of Boost C++ Library used to check whether the given type is an array type or not. It returns a boolean value showing the same. Header Files: #include "boost/type_traits/is_array.hpp" or #include "boost/type_traits.hpp" Template Class: template <class T> struc 3 min read Like