in Programming in C edited by
1,471 views
1 vote
1 vote

What is the value of the arithmetic expression (Written in C)

$2*3/4-3/4*2$

  1. $0$
  2. $1$
  3. $1.5$
  4. None of these
in Programming in C edited by
1.5k views

5 Answers

4 votes
4 votes
Best answer

In C Programming $*,/$ have equal precedence, and associativity is left to right.  The minus (-) operator has lower precedence than $*, /$ operator, and associativity is left to right.

Note: we use associativity rule when more than 2 operator having same precedence.

Also, in C language the result of applying a binary operator on integer types (both operands being integers) is ALWAYS INT irrespective of the operation. i.e, $5/2 = 2$ and not $2.5$ as one would normally expect.

$(((2*3)/4)-((3/4)*2))$

$((6/4)-((3/4)*2))$

$(1-((3/4)*2))$

$(1-(0*2))$

$(1-0)$

$1$

Option $B$ is correct.

Operator Precedence and Associativity in C

selected by
1 vote
1 vote
Option b is the correct answer

2*3/4-3/4*2 precedence of * /is same and associativity is left to right.

6/4-3/4*2

1-0*2

1-0

1
0 votes
0 votes
infix-> postfix evaluation

2*3/423/4* 2

=6/423/4* 2

=0/4*2

=0*2

=0 (OPTION A)
0 votes
0 votes

/ and * has equal priority and associativity is left to right

2*3/423/4*2

6/423/4*2

0/4*2

0*2

0

So answer is A)

here is code if you want to run

#include <stdio.h>
int main()
{
    int c=2*3/423/4*2;
    printf("%d",c);
    return 0;
}

2 Comments

But its answer is 1.
0
0
It is general method of solving and i did ran on 2 different ide code chef and tutorial point both give answer 0.

And expression are generally solved in this way, i am sure about precedence and associative
0
0