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. bool?

bool?

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 6 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.
  • D Offline
    D Offline
    dec82
    wrote on last edited by
    #1

    what is the meaning of '?'and ':' in this expression? bool Addr int m= Addr ? 1 : 5 thanks

    D H A J C 5 Replies Last reply
    0
    • D dec82

      what is the meaning of '?'and ':' in this expression? bool Addr int m= Addr ? 1 : 5 thanks

      D Offline
      D Offline
      dehseth
      wrote on last edited by
      #2

      means: int m; if (Addr) { m = 1; } else { m = 5; } check Addr (? -> check) if its true use first expression (1) else use second one (5)

      1 Reply Last reply
      0
      • D dec82

        what is the meaning of '?'and ':' in this expression? bool Addr int m= Addr ? 1 : 5 thanks

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        X1 ? answer1 : answer2 If X1 is true the expression will return answer1, if it is not it will return answer2 and I think you are new so see C++ Reference[^].

        Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

        1 Reply Last reply
        0
        • D dec82

          what is the meaning of '?'and ':' in this expression? bool Addr int m= Addr ? 1 : 5 thanks

          A Offline
          A Offline
          a_kiani
          wrote on last edited by
          #4

          This line of code first evaluates the condition 'Addr == true'. Then, if the condition is true assigns 1 to m, otherwise asssigns 5 to it.

          1 Reply Last reply
          0
          • D dec82

            what is the meaning of '?'and ':' in this expression? bool Addr int m= Addr ? 1 : 5 thanks

            J Offline
            J Offline
            Jijo Raj
            wrote on last edited by
            #5

            the ?: is a ternary operator(takes three operands), which is known as Conditional Operator. Its the simplified form of a simple if statement. Check the MSDN Link[^] for more info. Regards, Jijo.

            _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

            1 Reply Last reply
            0
            • D dec82

              what is the meaning of '?'and ':' in this expression? bool Addr int m= Addr ? 1 : 5 thanks

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              It actually means you need a good C tutorial. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              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