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. Please determine the output

Please determine the output

Scheduled Pinned Locked Moved Managed C++/CLI
c++javahelp
13 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.
  • C Christian Graus

    Sushant Duggal wrote:

    cout< This code is making some assumptions that are now being shown for it to compile as C++. It's not going to compile for Java. Beyond that, I agree with the other reply, you need to do your own homework.

    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

    S Offline
    S Offline
    Sushant Duggal
    wrote on last edited by
    #4

    Thanks for your reply friends, But I just want to know the reason why the outputs differ. i In C++, The result is x=18.y=7 where as in Java, The result is x=19, and y=7 I want to know the reason for this output. Is there a difference of stack implementation in the two languages or there is some other reason.. Please let me know. Thanks,

    Sushant Duggal.

    C 1 Reply Last reply
    0
    • S Sushant Duggal

      Thanks for your reply friends, But I just want to know the reason why the outputs differ. i In C++, The result is x=18.y=7 where as in Java, The result is x=19, and y=7 I want to know the reason for this output. Is there a difference of stack implementation in the two languages or there is some other reason.. Please let me know. Thanks,

      Sushant Duggal.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #5

      ++x guarentees that the number is incremented before it's returned. x++ guarentees it's incremented after, but not how LONG after.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      S 2 Replies Last reply
      0
      • C Christian Graus

        ++x guarentees that the number is incremented before it's returned. x++ guarentees it's incremented after, but not how LONG after.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        S Offline
        S Offline
        Sushant Duggal
        wrote on last edited by
        #6

        Yes, I agree on your comment. so do you want to say that there is no method to determine the value?

        Sushant Duggal.

        1 Reply Last reply
        0
        • C Christian Graus

          ++x guarentees that the number is incremented before it's returned. x++ guarentees it's incremented after, but not how LONG after.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          S Offline
          S Offline
          Sushant Duggal
          wrote on last edited by
          #7

          OK now i got the point. its correct to get 19 in C++, but I still didnt understand why it comes 18 in java. Can you comment on this? Thanks

          Sushant Duggal.

          C 1 Reply Last reply
          0
          • S Sushant Duggal

            OK now i got the point. its correct to get 19 in C++, but I still didnt understand why it comes 18 in java. Can you comment on this? Thanks

            Sushant Duggal.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #8

            I believe it goes like this: The ++ operator occurs in both languages AFTER x is given it's final value. The difference is that in Java, the values are by reference, so the value that x is assigned to, is the value that still has a ++ operator outstanding. so, x gets set to 18. y gets incremented, to 7, and x also gets incremented, but it's the same x that is 18, not a copy of x which is 16.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            1 Reply Last reply
            0
            • S Sushant Duggal

              Hi friends, Can anyone tell me what will be the output of the folloing code and whats the reason for that. It will be a great help. int x = 12; int y = 6; x = x++ + y++ cout< can you tell me the output for C++ and Java compiler and whats the reason for the answer. Thanks in Advance Sushant Duggal.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #9

              Oh - you also posted in the wrong forum, I didn't notice before.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              S 1 Reply Last reply
              0
              • C Christian Graus

                Oh - you also posted in the wrong forum, I didn't notice before.

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                S Offline
                S Offline
                Sushant Duggal
                wrote on last edited by
                #10

                Then where I would have posted this?

                Sushant Duggal.

                C 1 Reply Last reply
                0
                • S Sushant Duggal

                  Then where I would have posted this?

                  Sushant Duggal.

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #11

                  Managed C++/CLI is the forum for discussion of .NET C++, as it clearly states. This[^] is the general C++ forum.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                  S 1 Reply Last reply
                  0
                  • C Christian Graus

                    Managed C++/CLI is the forum for discussion of .NET C++, as it clearly states. This[^] is the general C++ forum.

                    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                    S Offline
                    S Offline
                    Sushant Duggal
                    wrote on last edited by
                    #12

                    The ++ operator occurs in both languages AFTER x is given it's final
                    value. The difference is that in Java, the values are by reference, so
                    the value that x is assigned to, is the value that still has a ++ operator outstanding. so, x gets set to 18. y gets incremented, to 7,
                    and x also gets incremented, but it's the same x that is 18, not a
                    copy of x which is 16.

                    I can understand that in java, the values are by reference. that means X is incremented direectly where it is stored, it sets it to 12 + 6 = 18. Confusion ..... when the X is going to incremented? and why it is not reflected(X's value is still 18). Thanks For your Patience, Sushant Duggal. -- modified at 3:39 Thursday 28th September, 2006

                    Sushant Duggal.

                    1 Reply Last reply
                    0
                    • S Sushant Duggal

                      Hi friends, Can anyone tell me what will be the output of the folloing code and whats the reason for that. It will be a great help. int x = 12; int y = 6; x = x++ + y++ cout< can you tell me the output for C++ and Java compiler and whats the reason for the answer. Thanks in Advance Sushant Duggal.

                      N Offline
                      N Offline
                      Nish Nishant
                      wrote on last edited by
                      #13

                      The statement i = i++ has undefined behavior in C++ and different compilers can generate different code and still be standards compliant. The = operator does not define a separate sequence point, and C/C++ rules dictate that an expression can modify an object's value only once within a single sequence point - else the compiler's free to interpret the code in whatever way it wants to.

                      Regards, Nish


                      Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                      Currently working on C++/CLI in Action for Manning Publications. Also visit the Ultimate Toolbox blog

                      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