Get variables' types at runtime in C

一世执手 提交于 2019-12-12 05:49:38

问题


Can I get in C the program variables' types those existing in a specific memory segment at runtime.

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.


回答1:


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

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, there's another type conversion in the code above, that is:

float s = 3.4;

because 3.4 is of type double.



来源:https://stackoverflow.com/questions/19753407/get-variables-types-at-runtime-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!