0

What I know:

#include <iostream>
#include <typeinfo>
using namespace std;

int main()  
{    
    int a = 3;
    const int& b = 4;
    cout<<typeid(a).name()<<endl;
    cout<<typeid(b).name()<<endl;
}

So this will going to print:

i    // i stands for int
i    

But my question is what can I do to print the exact type of b?

This is what I tried :

#include <iostream>
#include <typeinfo>
using namespace std;

int main()  
{    
    int a = 3;
    const int& b = 4;
    cout<<typeid(a).name()<<endl;
    cout<<typeid(b).name()<<endl;
    
    decltype(b) k = 4;
    cout<<typeid(k).name()<<endl;
    return 0;
}

but still, the output is :

i
i
I

I mean isn't there any function for efficiently getting the type of variable...

  • 1
    See [how to make `cout << typeof(5) << endl;` print `int`](https://stackoverflow.com/questions/81870/is-it-possible-to-print-a-variables-type-in-standard-c). – Jason Oct 22 '22 at 06:05
  • 2
    Do not spam all the different version-specific c++ tags. As indicated by the description of the `c++11` tag, "Use this tag for code that must compile as C++11 (not using any features introduced in C++14 or later)." – kotatsuyaki Oct 22 '22 at 06:40
  • @kotatsuyaki oh sorry, I got this... – Aditya Gaikwad Oct 22 '22 at 07:36

0 Answers0