Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. operato precendance question

operato precendance question

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amrit Agr
    wrote on last edited by
    #1

    Hi developers, I am interested to so solve this chunk of code void main() { int Var = 90; if(Var += Var == ++Var == 89) printf(" %d ",Var); } After executing the code i m getting the answer "91" I am really surprised with the answer. Infact, I am not clear with operator precedence in this problem. Please give some help for it. Thanks. Amrit Agrawal, Mumbai

    L J S 3 Replies Last reply
    0
    • A Amrit Agr

      Hi developers, I am interested to so solve this chunk of code void main() { int Var = 90; if(Var += Var == ++Var == 89) printf(" %d ",Var); } After executing the code i m getting the answer "91" I am really surprised with the answer. Infact, I am not clear with operator precedence in this problem. Please give some help for it. Thanks. Amrit Agrawal, Mumbai

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The rules are that expressions such as this may lead to incorrect results. You need to split it into constituent parts.

      One of these days I'm going to think of a really clever signature.

      1 Reply Last reply
      0
      • A Amrit Agr

        Hi developers, I am interested to so solve this chunk of code void main() { int Var = 90; if(Var += Var == ++Var == 89) printf(" %d ",Var); } After executing the code i m getting the answer "91" I am really surprised with the answer. Infact, I am not clear with operator precedence in this problem. Please give some help for it. Thanks. Amrit Agrawal, Mumbai

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        Amrit Agr wrote:

        Please give some help for it.

        Rewrite it so it is more maintainable.

        1 Reply Last reply
        0
        • A Amrit Agr

          Hi developers, I am interested to so solve this chunk of code void main() { int Var = 90; if(Var += Var == ++Var == 89) printf(" %d ",Var); } After executing the code i m getting the answer "91" I am really surprised with the answer. Infact, I am not clear with operator precedence in this problem. Please give some help for it. Thanks. Amrit Agrawal, Mumbai

          S Offline
          S Offline
          skrtbhtngr
          wrote on last edited by
          #4

          void main()
          {
          int Var = 90;
          if(Var += (((Var == (++Var)) == 89)))
          printf(" %d ",Var);
          }

          Operator precedence: 1. Increment operator (++) 2. Relational operator (==), and its Associativity is Left to Right 3. Assignment operator (+=) Hope it helps...:thumbsup:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups