I was checking some types of variables and got some confusing results:
#include <iostream>
#include <typeinfo>
using namespace std;
int main(void) {
int number = 5;
int* pointer = &number;
cout << typeid(number).name() << endl; // i
cout << typeid(pointer).name() << endl; // Pi
cout << typeid(&pointer).name() << endl; // PPi
return 0;
}
The i
means int
, but what do Pi
and PPi
mean? Pointer int
?
The typeid operator returns an lvalue of type const std::type_info that represents the type of expression expr. You must include the standard template library header <typeinfo> to use the typeid operator. Classes A and B are polymorphic; classes C and D are not.
typeid( object ); The typeid operator is used to determine the class of an object at runtime. It returns a reference to a std::type_info object, which exists until the end of the program, that describes the "object".
The typeid operator allows the type of an object to be determined at run time. The result of typeid is a const type_info& . The value is a reference to a type_info object that represents either the type-id or the type of the expression, depending on which form of typeid is used.
It means pointer to an integer and pointer to a pointer to an integer, respectively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With