How to know the type of a variable in C++?

To check the type of a variable in C++, you can use typeid(variable).name(), for example

 #include <typeinfo>
...
...

   int b=9;
    char c='a';
    char * p=&c;
    int *d;
    printf("%s\n",typeid(b).name());
    printf("%s\n",typeid(c).name());
    printf("%s\n",typeid(p).name());
    printf("%s\n",typeid(d).name());
  • the typeid of variables of int type is i
  • the typeid of variables of char type is c
  • the typeid of pointers of type char * is Pc
  • the typeid of pinters of type int * is Pi

reference: https://stackoverflow.com/questions/11310898/how-do-i-get-the-type-of-a-variable

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:

Leave a Reply