help for my exam. easy question

This is a discussion on help for my exam. easy question within the C Programming forums, part of the General Programming Boards category; what does the question mark mean also what is the exclamation, and the colon. Code: int a; a =(6>3) ? ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    62

    help for my exam. easy question

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

    Code:
    int a;
    a =(6>3) ? 3 ! =5 : 9;
    printf("%i",a);

    question #2

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

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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
    Location
    Katy, Texas
    Posts
    2,309
    { 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?

    Code:
     
    	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
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    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
    Location
    Canada
    Posts
    8,046
    dwk

    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: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    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, 12: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

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