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. C / C++ / MFC
  4. Why ?

Why ?

Scheduled Pinned Locked Moved C / C++ / MFC
csharphelpquestionvisual-studio
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.
  • S Offline
    S Offline
    Sofian Teja
    wrote on last edited by
    #1

    :doh: int test = 1 + 2 + 3; +2 + 3 +4; after I compile with Visual studio 6 or .net the answer test is 6 Is there anyone know what is weird ? the compiler will not have any error message, is this kind of bug ? Thanks for advance.

    coding is just the beginning

    O M M 3 Replies Last reply
    0
    • S Sofian Teja

      :doh: int test = 1 + 2 + 3; +2 + 3 +4; after I compile with Visual studio 6 or .net the answer test is 6 Is there anyone know what is weird ? the compiler will not have any error message, is this kind of bug ? Thanks for advance.

      coding is just the beginning

      O Offline
      O Offline
      OregonGhost
      wrote on last edited by
      #2

      Of course int test = 1 + 2 + 3; equals 6. +2 + 3 +4; is a seperate expression. Remove the first semicolon if you want to connect the two expressions. int test = 1 + 2 + 3 +2 + 3 +4; will result in test == 15.

      1 Reply Last reply
      0
      • S Sofian Teja

        :doh: int test = 1 + 2 + 3; +2 + 3 +4; after I compile with Visual studio 6 or .net the answer test is 6 Is there anyone know what is weird ? the compiler will not have any error message, is this kind of bug ? Thanks for advance.

        coding is just the beginning

        M Offline
        M Offline
        Moak
        wrote on last edited by
        #3

        Sofian Teja wrote:

        int test = 1 + 2 + 3;

        Evaluates to 6 (according to Adam Riese).

        Sofian Teja wrote:

        +2 + 3 +4;

        Is an empty expression (it does nothing), always switch on your compiler warnings and you will be notified when such things happen accidentally. Related articles: Getting pragmatic with warnings, here and here. Hope it helps.

        1 Reply Last reply
        0
        • S Sofian Teja

          :doh: int test = 1 + 2 + 3; +2 + 3 +4; after I compile with Visual studio 6 or .net the answer test is 6 Is there anyone know what is weird ? the compiler will not have any error message, is this kind of bug ? Thanks for advance.

          coding is just the beginning

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Any expression can also be a statement. The statement +2 + 3 +4; is perfectly legal. It calculates the value and does nothing with it. (Of course, in optimized builds, the statement will be removed since it does nothing and has no side effects.)

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.

          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