小编Ano*_*non的帖子

在C中确定运行期间变量的类型

我有几个char(array),int和double类型的变量.有没有办法确定它们在运行时的类型?

例如,我正在寻找类似的东西:

int dummyInt = 5;    
double dummyDouble = 5.0;    
dummyInt == int ?
        printf("yes, it's of int type\n") : printf("no, it's not of int type\n");
dummyDouble == int ?
        printf("yes, it's of int type\n") : printf("no, it's not of int type\n");
Run Code Online (Sandbox Code Playgroud)

显而易见的结果将是:

是的,它是int类型
否,它不是int类型

好吧,我需要它的原因是因为我将数据从变量传输到SQL数据库(使用SQLite).现在,每次运行程序时标头都会改变,具体取决于使用的变量.因此,当我创建表时,我需要告诉它是否为VARCHAR,INTEGER,DOUBLE等.

c types runtime

1
推荐指数
1
解决办法
1635
查看次数

标签 统计

c ×1

runtime ×1

types ×1