typeid Operator – Type Casting

typeid Operator – Type Casting

How is typeid operator used in C++?

Explanation

typeid operator is a type casting method which is used to check the type of an expression. In C++, the typeid keyword is used to determine the class of an object at runtime

Example :

#include
#include
int main()
{
int a;
char *c;
cout << "The type of a is: " << typeid(a).name() << endl;
cout << "The type of c is: " << typeid(c).name() << endl;
return 0;
}

Result :

The type of a is: int
The type of c is: char *

In the above example the “typeid” is used to find the data type.





Leave a Reply

Your email address will not be published. Required fields are marked *