-4

This is a really simple question, but I'm afraid it's a bit tricky.

Which of the following symbols has the highest precedence? (C++)

a. %

b. -

c. ||

d. &&

I know it sounds easy, but I'm really wondering if whether the answer is % or -. The symbol - can be seen as either a unary minus (which is higher than %) or subtraction (which is lower than %).

What do you think?

bffaf01
  • 27
  • 1
  • 1
  • 1
  • 3
    Sorry, was too hasty. The question is ill-posed for the reason you state. Whoever made that question messed up. – Baum mit Augen Jan 21 '17 at 02:15
  • Circle a and b and make a note on the paper that it depends on whether `-` is the unary negation or binary subtraction operator. If it's an online assignment that won't let you choose two or leave an extra note, most system have a comments section for the quiz as a whole (or a way to contact the setter). Just leave them a note there. – paxdiablo Jan 21 '17 at 02:33
  • Possible duplicate of [Who defines C operator precedence and associativity?](http://stackoverflow.com/questions/20767745/who-defines-c-operator-precedence-and-associativity) –  Jan 21 '17 at 04:33

2 Answers2

-1

A google search for c++ Operator Precedence yielded this: http://en.cppreference.com/w/cpp/language/operator_precedence

According to the link, Multiplication, division, and remainder come before Addition and subtraction and further down the list comes the Bitwise operations found in row 5,6,13, and 14 respectively.

Semaphore
  • 63
  • 1
  • 12
-2

I would assume the person who made this question wanted you to choose the operator that has the highest possible precedence.

I would choose b.

cppxor2arr
  • 295
  • 2
  • 12