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. what the hell is this and why

what the hell is this and why

Scheduled Pinned Locked Moved Managed C++/CLI
4 Posts 3 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.
  • K Offline
    K Offline
    keshava shukla
    wrote on last edited by
    #1

    when you type a code int a =10; printf("%d %d %d",a++,a++,a++); returns o/p 12 11 10 can anybody pls xplain me why this o/p comes:doh:

    T B 2 Replies Last reply
    0
    • K keshava shukla

      when you type a code int a =10; printf("%d %d %d",a++,a++,a++); returns o/p 12 11 10 can anybody pls xplain me why this o/p comes:doh:

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      C++ don't tell in which order the parameters are passed... here your compiler passes the last parameter first, so, this is why the last a++ gives you 10. as you can see, never make such assertion in your code, and never write such code, because it will behave different ways depending on the compiler you built your code.


      TOXCCT >>> GEII power
      [toxcct][VisualCalc]

      1 Reply Last reply
      0
      • K keshava shukla

        when you type a code int a =10; printf("%d %d %d",a++,a++,a++); returns o/p 12 11 10 can anybody pls xplain me why this o/p comes:doh:

        B Offline
        B Offline
        bugDanny
        wrote on last edited by
        #3

        keshava shukla wrote: int a =10; printf("%d %d %d",a++,a++,a++); returns o/p 12 11 10 Funny. I tested this and what I got to print out was: 10 10 10 That would be the behavior I would expect, since those are postfix (++) operators, they should be incremented after the printf() expression. I made sure and put a cout << a; statement after the printf() statement, and sure enough a was 13. Are you using C, or C++. The ++ is much more unpredictable in C. As the other person that responded said, just don't do it. If you have to, make three extra values, like a1, a2, a3, and increment a and assign it to each of those values and pass those into printf. Danny

        K 1 Reply Last reply
        0
        • B bugDanny

          keshava shukla wrote: int a =10; printf("%d %d %d",a++,a++,a++); returns o/p 12 11 10 Funny. I tested this and what I got to print out was: 10 10 10 That would be the behavior I would expect, since those are postfix (++) operators, they should be incremented after the printf() expression. I made sure and put a cout << a; statement after the printf() statement, and sure enough a was 13. Are you using C, or C++. The ++ is much more unpredictable in C. As the other person that responded said, just don't do it. If you have to, make three extra values, like a1, a2, a3, and increment a and assign it to each of those values and pass those into printf. Danny

          K Offline
          K Offline
          keshava shukla
          wrote on last edited by
          #4

          thanks i think it will work

          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