I just met a problem in C. Following is the code:
#include <stdio.h>
int main() {
double num = 0;
printf("Please enter a number: ");
scanf("%f", &num);
printf("The entered number is %f", num);
return 0;
}
For some reason, no matter what number is entered from keyboard, the value of num keeps the same as 0. Of course, if I change the data type of num to float, then everything will be fine. But I just want to know why the above code does not work. My understanding is C automatically converts float to double, so the above code should work fine. I wonder if anybody can kindly provide further explanation.
Thanks.