Please read the new rule regarding the restriction on the use of AI tools. ×

_noor_a_alam_'s blog

By _noor_a_alam_, history, 8 months ago, In English

How can I find a type of a variable in C++?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Code:

#include <iostream>
#include <typeinfo>

using namespace std;

int main() {
	int a = 10;
	double b = 10.12;
	float c = 10.22;
	
	cout << typeid(a).name() << '\n';
	cout << typeid(b).name() << '\n';
	cout << typeid(c).name() << '\n';
}

Output:

i
d
f
»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Tip: Googling will get you answers quicker. As a coder, building this practice will help in the future.