I have absolutely no idea why it returns 2 for a=2 and b=2..
Any ideas?
#include <stdlib.h>
int main()
{
double a,b,c;
printf("a=");
scanf("%d", &a);
printf("b=");
scanf("%d", &b);
printf("c=");
scanf("%d", &c);
printf("x=%d", a+b);
return 0;
}
The specifier
"%d"expects an integer and you are passing the address of adouble. Using the wrong specifiers inscanfleads to undefined behavior.Also, using the wrong specifier in
printfis the same thing. Becauseprintftakes a variable number of argumentsa + bwhich is a double can’t be converted to an integer.