get type of variable in c++

To get the type of a variable in C++, you can use the typeid operator along with the name() function. Here are the steps to do it:

  1. Include the <typeinfo> header file in your program to use the typeid operator and the name() function.
#include <typeinfo>
  1. Declare a variable whose type you want to determine.
int num = 10;
  1. Use the typeid operator followed by the name() function to get the type of the variable. Assign the result to a const char* variable.
const char* typeName = typeid(num).name();
  1. Print the type name using the typeName variable.
std::cout << "Type of variable: " << typeName << std::endl;

By executing these steps, you will be able to obtain the type of a variable in C++.