C code, don't understand a command

This is a discussion on C code, don't understand a command within the C Programming forums, part of the General Programming Boards category; Hi I'm a beginner and I'm tryng to exercise with some books and small programs. I've found a simple progam ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    56

    C code, don't understand a command

    Hi

    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:

    Code:
    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

    D.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,407
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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

    Thanks
    D.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    It's the same as
    Code:
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 11:51 AM
  5. feel free to laugh at my code!
    By JimJamJovi in forum C Programming
    Replies: 4
    Last Post: 01-11-2002, 03:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21