问题
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