Thread: help for my exam. easy question

  1. #1
    Registered User
    Join Date
    Feb 2008

    help for my exam. easy question

    what does the question mark mean also what is the exclamation, and the colon.

    int a;
    a =(6>3) ? 3 ! =5 : 9;

    question #2

    Also, i dont understand how this if... else can be the answer can someone explain this to me.
    a=(6>3) ? 3 !=5 : 9;

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    The if-else means the same thing as the ?: ternary operator (I just like typing the word "ternary") -- except the last symbol should be 9.

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Katy, Texas
    { optional assignment = } conditional_expression ? true_expression : false_expression ;

    If the conditional expression evaluate to true, then the "true_expression" following the question mark is evaluated. Otherwise, the "false_expression" following the colon is evaluated.

    These things can nest and get ugly as well. Perhaps this is an extra credit question on your test: What will answer print as?

    	int answer ; 
    	int a = 6 ; 
    	int b = 8 ; 
    	answer = (b > a) ? a < b ? 0 : 7 : b == a ? 1 : 5;    
    	printf ("answer is &#37;d\n", answer) ;
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    That's a clear abuse of the operator and should be avoided, just to be noted.
    Todd is doing it on purpose to confuse and test! If you pass the test, then surely you shall pass your exam!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. This is hopefully an extremely easy question...
    By rachaelvictoria in forum C Programming
    Replies: 2
    Last Post: 11-07-2005, 01:36 AM
  2. 4 easy question
    By Zeratulsdomain in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2005, 10:43 PM
  3. Easy Question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 08-12-2002, 12:19 PM
  4. I have a 2 easy question about some homework?
    By correlcj in forum C Programming
    Replies: 3
    Last Post: 07-18-2002, 07:28 PM
  5. exam question
    By teja22 in forum C Programming
    Replies: 2
    Last Post: 10-08-2001, 08:03 PM