Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the output of typeid().name()

Tags:

c++

types

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?

like image 937
Evgenij Reznik Avatar asked Apr 28 '13 21:04

Evgenij Reznik


People also ask

What does Typeid return?

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.

What does Typeid name return C++?

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".

What is the use of Typeid () function?

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.


2 Answers

It means pointer to an integer and pointer to a pointer to an integer, respectively.

like image 134
Captain Obvlious Avatar answered Oct 16 '22 06:10

Captain Obvlious


  • i: integer
  • Pi: pointer to integer variable
  • Ppi: pointer to a pointer to integer variable
like image 24
Miguel Prz Avatar answered Oct 16 '22 05:10

Miguel Prz