Thread: C code, don't understand a command

  1. #1
    Registered User
    Join Date
    Jun 2009

    C code, don't understand a command


    I'm a beginner and I'm tryng to exercise with some books and small programs.
    I've found a simple progam that contain this code line:

    res = (occur == answer)? 1 : 0;
    but i can't understand the meaning of " ? 1 : 0 ", and i can't find it into the book.
    Can anyone help please?

    thanks in advance


  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    You could search your book's index for "conditional operator" or "ternary operator". Anyway, in this case it is redundant since occur == answer evaluates to 1 or 0.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2009
    perfect, I found it!!


  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    It's the same as
    res = (occur == answer);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  2. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  3. problem with "touch" command in c program
    By Moony in forum C Programming
    Replies: 10
    Last Post: 08-01-2006, 09:56 AM
  4. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM
  5. feel free to laugh at my code!
    By JimJamJovi in forum C Programming
    Replies: 4
    Last Post: 01-11-2002, 04:40 AM