how to check datatype of a variable in c++

#include <iostream>
#include <typeinfo>

int main() {
    // Declare a variable
    int myVariable = 42;

    // Use typeid to get the data type information
    const std::type_info& typeInfo = typeid(myVariable);

    // Use name() to get the type name as a string
    const char* typeName = typeInfo.name();

    // Print the data type information
    std::cout << "Variable has type: " << typeName << std::endl;

    return 0;
}