0

I'm getting PKc as the output when providing typeid(check).name() - where check is a char variable - as the argument to typeid.name()

#include<bits/stdc++.h>
using namespace std;
main()
{ 
    char check='e';
   cout<<typeid(check).name()<<"\n";
   cout<<typeid(typeid(check).name()).name();
}

output

c
PKc

Getting it even on changing the type of check from char to double

#include<bits/stdc++.h>
using namespace std;
main()
{ 
    double check=69.666;
   cout<<typeid(check).name()<<"\n";
   cout<<typeid(typeid(check).name()).name();

}

output

d
PKc

P.S. The solution suggested by @AsteroidsWithWings does provide the bare-bones of the underlying concepts but doesn't specifically answers what "PKc" means.

  • Does this answer your question? [typeid("") != typeid(const char\*)](https://stackoverflow.com/questions/56564321/typeid-typeidconst-char) – Adrian Mole Dec 19 '20 at 12:24
  • Don't rely on `typeid.name()`, implementation of this function isn't standardized (library specific). – bloody Dec 19 '20 at 12:27
  • @AdrianMole No. I actually perused that question before asking this one – Petruso Kadyrov Dec 19 '20 at 12:57
  • **Recommended reading:** [Why should I not #include ?](https://stackoverflow.com/q/31816095/560648) – Asteroids With Wings Dec 19 '20 at 14:08
  • Does this answer your question? [Why does typeid.name() return weird characters using GCC and how to make it print unmangled names?](https://stackoverflow.com/questions/4465872/why-does-typeid-name-return-weird-characters-using-gcc-and-how-to-make-it-prin) – Asteroids With Wings Dec 19 '20 at 14:09

2 Answers2

2

PKc is the mangled name of const char*. P is the encoding for "pointer", K refers to "const", and c means "char".

See also Why does typeid.name() return weird characters using GCC and how to make it print unmangled names?.

cpplearner
  • 10,463
  • 2
  • 34
  • 57
0

That string is returned from a std::type_info::name() function call. The result of that function is implementation-specific, that is the C++ standard does not require all compilers to return some specific string. Instead, each compiler is allowed to invent its own string representation of C++ type names. Compilers are not required to make that string easily readable.

Very likely, "PKc" is the string that your particular compiler is using to represent const char* type, which is the return type of std::type_info::name() function.

Igor G
  • 1,484
  • 2
  • 14