Get variables' types at runtime in C

2019-09-01 13:32发布

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条回答
Deceive 欺骗
2楼-- · 2019-09-01 13:48

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.

查看更多
登录 后发表回答