I was implementing a small cmd calculator in Objective-C for OOP practice. I was getting input for doubles via scanf() and to get the input, I used %f for formatting then put it in a double variable. For some reason it would always read the input odd. I don’t know what was going on but when I changed all of the types to int, it worked out perfectly.
I was implementing a small cmd calculator in Objective-C for OOP practice. I was
Share
The
scanf()format for double is"%lf".printf()can use the same"%f"format for bothfloatanddouble, becausefloatarguments to variadic functions are promoted todouble. There’s no such promotion forscanf()because you’re passing a pointer, and you need to have an actualfloatordoubleobject in memory.