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. what is the ? thingy called?

what is the ? thingy called?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
6 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.
  • K Offline
    K Offline
    keegan
    wrote on last edited by
    #1

    Ok, i saw the ? thing used in some code, and i dont know what it does. I tried googling, but, um, i dont know what its called, and you cant google for "c++ ?" very easily. So, what is it called so i can google for it lol. *.* cin >> knowledge;

    Z M L 3 Replies Last reply
    0
    • K keegan

      Ok, i saw the ? thing used in some code, and i dont know what it does. I tried googling, but, um, i dont know what its called, and you cant google for "c++ ?" very easily. So, what is it called so i can google for it lol. *.* cin >> knowledge;

      Z Offline
      Z Offline
      ZoogieZork
      wrote on last edited by
      #2

      You mean like: int foo = (blah == 2) ? 1 : 0; or something like that? If so, that's a conditional expression, referred to variously as "immediate if", the "ternary operator", the "conditional operator", or simply the "?:" operator. It's basically an "if..then..else" type of expression that returns a value. Users of functional languages are very familiar with doing conditionals like this. - Mike

      1 Reply Last reply
      0
      • K keegan

        Ok, i saw the ? thing used in some code, and i dont know what it does. I tried googling, but, um, i dont know what its called, and you cant google for "c++ ?" very easily. So, what is it called so i can google for it lol. *.* cin >> knowledge;

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

        Search for "ternary operator". It ought to be called a "trinary operator" since it takes 3 arguments, but the incorrect term "ternary" has stuck for whatever reason. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 released

        K 1 Reply Last reply
        0
        • M Michael Dunn

          Search for "ternary operator". It ought to be called a "trinary operator" since it takes 3 arguments, but the incorrect term "ternary" has stuck for whatever reason. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 released

          K Offline
          K Offline
          keegan
          wrote on last edited by
          #4

          ok, so in the example above, it basically means (if blah == 2) { foo = 1; } else { foo = 0; } pretty neat...thanks-o. *.* cin >> knowledge;

          M 1 Reply Last reply
          0
          • K keegan

            Ok, i saw the ? thing used in some code, and i dont know what it does. I tried googling, but, um, i dont know what its called, and you cant google for "c++ ?" very easily. So, what is it called so i can google for it lol. *.* cin >> knowledge;

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

            Hi, do you mean the ? : operator????:) This is just an abbreviation for an if else statement used in C++. Consider the following for example: return x = a ? b< c : d > a; In this case x is either (ba) depending on the programming return value. Hope it helps. Regards. Alex

            1 Reply Last reply
            0
            • K keegan

              ok, so in the example above, it basically means (if blah == 2) { foo = 1; } else { foo = 0; } pretty neat...thanks-o. *.* cin >> knowledge;

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

              That is correct :) --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 released

              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