Understanding the output of typeid (). Name ()

I checked 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; } 

i means int , but what do Pi and PPi mean? Pointer int ?

+4
source share
3 answers

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

+5
source
  • i: integer
  • Pi: pointer to an integer variable
  • Ppi: pointer to a pointer to an integer variable
+4
source

The material that appears after the double slash is a comment.

eg.

 int main() { int i = 0; // This is a comment. // This is also a comment. // i // The above line is a comment. // PPi // The above line is ALSO a comment. return 0; } 

Hope this clarifies a bit.

However, the one who wrote this code should mean that I refer to integer, Pi refers to a pointer to an integer, and PPi means a pointer to a pointer to an integer.

-6
source

All Articles