Urgenthomework logo
UrgentHomeWork
Live chat

Loading..

C Homework help

Order of precedence

Following is the order of precedence in C:

Order of precedence

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 */}
#include <stdio.h>
#include <conio.h>
int main()
{
{//}int a, ans1, ans2;
float b, ans3, ans4;
char c;
printf(“Enter an integer, a=”);
scanf(“%d”,&a);
printf(“\nEnter a float, b=”);
scanf(“%f”,&b);
printf(“\nEnter a char, c=”);
scanf(“%c”,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);
getch();
return;
}

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.

Order of precedence Homework Help

Topics in C Programming

Copyright © 2009-2023 UrgentHomework.com, All right reserved.