-1

int x=10 and after run the code show "10 int"

    #include<stdio.h>
    int main()
    {
        int x=10;
        printf("%d %s",x,typedef(x))
    }

1 Answers1

4

C doesn't have any run-time type information. The best you can achieve with standard C is to manually list all supported types at compile-time, then at compile-time check which one that was used. Example:

#include <stdio.h>

#define TYPE_STR(x) _Generic((x), \
  int:    "int",                  \
  double: "double",               \
  char:   "char" )                \

int main()
{
  int x=10;
  printf("%d %s",x,TYPE_STR(x));
}
Lundin
  • 195,001
  • 40
  • 254
  • 396