Following is the order of precedence in C:
High priority operators are evaluated before lower priority ones. Operators of the same priority are evaluated from left to right
/* Sample C program to illustrate concepts described above */
int a, ans1, ans2;
float b, ans3, ans4;
printf(“Enter an integer, a=”);
printf(“\nEnter a float, b=”);
printf(“\nEnter a char, c=”);
ans1 = a + b * c;
ans2 = a + b – c;
ans3 = a * b – c;
ans4 = a – b + c;
printf(“\nans1 = %d\nans2 = %d\nans3 = %-f\nans4 = %-f”,ans1,ans2,ans3,ans4);
In this program we are performing Mathematical Operation on a char, what will happen?
It won’t give any error rather it will take the ASCII value of that char and will perform operation on that.
You might get some problems with scanf in case of char, with some compilers. There are other methods to get that done which we will discuss later.
Urgenthomework helped me with finance homework problems and taught math portion of my course as well. Initially, I used a tutor that taught me math course I felt that as if I was not getting the help I needed. With the help of Urgenthomework, I got precisely where I was weak: