使用C在运行时获取变量的类型 [英] Get variables' types at runtime in C
本文介绍了使用C在运行时获取变量的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在C中获取运行时在特定内存段中存在的程序变量类型。
Can I get in C the program variables' types those existing in a specific memory segment at runtime.
C无法识别以下错误:
C Does not recognize the error in:
int k=5;
float s= 3.4;
k=s;
printf("%d", k);
我正在尝试在运行时更改变量的类型。
I am trying to change the variables' types at runtime.
推荐答案
C是一种静态类型语言,您不能更改变量的类型。这段代码:
C is a static type language, you can't change a variable's type. This code:
int k=5;
float s= 3.4;
k=s; //type conversion
不更改 k
的类型, k
仍然是类型 int
,它所做的只是转换浮动
值( 3.4f
)到 int
(即 3
),并将 int
value 分配给 k
。
didn't change k
's type, k
is still of type int
, all it does is to convert the float
value (3.4f
) to an int
(which is 3
), and assign that int
value to k
.
BTW,上面的代码中还有另一种类型转换,即:
BTW, there's another type conversion in the code above, that is:
float s = 3.4;
因为 3.4
的类型为 double
。
这篇关于使用C在运行时获取变量的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文