Thread: what does ? character mean?

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    8

    what does ? character mean?

    hi sorry to ask such a basic question but what does the ? character do in c?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    It is one part of the trinary operator.

    Just like in the english language ? denotes a question.

    syntax is: condition ? true : false

    So basically its: is condition true? If true do the true statement, if not do the false statement

  3. #3
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    It is a handy operator that is not limited to output. An example in code

    Code:
    int items = 1;
    
    printf("you have %d %s remaining.", items, items > 1 ? "items" : "item");
    It's late for me, but the output *should* read: you have 1 item remaining.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  4. #4
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    They are also a part of trigraphs, some special sequences of three characters (most probably you won't ever need to use trigraphs)
    http://www.opus1.com/vmsdoc/progtool...igraph_seq_tab
    The one who says it cannot be done should never interrupt the one who is doing it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. syntax error when defining vectors
    By starkhorn in forum C++ Programming
    Replies: 5
    Last Post: 09-22-2004, 12:46 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM