#How can the answer be IC??

21 messages · Page 1 of 1 (latest)

glossy trout
#
What will be shown on the screen as a result of executing the following statements?
int x = 3;
if(x/2*2 == x)
   printf("NR");
else if(x/2*2 == 2/2*x)
   printf("ME");
else if(2/2*x == x)
   printf("IC");
else
   printf("KM");
A.    NR
B.    ME
C.    IC
D.    KM
prisma pythonBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

glossy trout
#

its supposed to be NR

#

order of operation is * / not / *

craggy charm
#

* and / have the same precedence

#

they evaluate left to right

glossy trout
#

if I switch order

#

I get different value?

#
  • /
    / *
craggy charm
#

wdym

glossy trout
#

x/2 * 2 is not the same as x * 2 / 2?

golden nova
#

no

#

x is int

glossy trout
#

no?

golden nova
#

int division truncates

#

3/2=1

#

get used to it

glossy trout
#

like // in python

craggy charm
#

yes

glossy trout
#

!close

prisma pythonBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity