c question

Discussion in 'C' started by pradeepjob, Mar 8, 2007.

  1. pradeepjob

    pradeepjob New Member

    Joined:
    Mar 8, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    can u print a statement without using a semi colon?
    a.Yes
    b.No
    c.Depends on the compiler
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Yes you can.
    Code:
    main()
    {
      if(printf("Print whatever you want here."))
      {
      }
    }
    This should generate one warning of main not returning anything but its not any error.
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    I realize your question says, "C compiler", but just for information purposes, a C++ compiler has different requirements. In a standards-compliant C++ compiler, failing to declare the return type of main will generate an error. That return type should properly be "int". Leaving off the return statement will not generate an error in a compliant C++ compiler; the compiler is required to provide it behind the scenes.

    All this has nothing to do with the semicolon question, of course. It's amazing how much logic one can put in an expression for an "if" or "while" construct.
     
  4. wrecker

    wrecker New Member

    Joined:
    Mar 12, 2007
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    0
    Another way to do it is using conditional operators. or ?:..... i hope that you would find satisfactory example.... if you do not know refer this code but its rough....
    (x>y)?(printf("\n\n X is greater than Y")):(printf("\n\n Y is greater than X"));
     
  5. wrecker

    wrecker New Member

    Joined:
    Mar 12, 2007
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    0
    Another way to do it is using conditional operators. or ?:..... i hope that you would find satisfactory example.... if you do not know refer this code but its rough....
    (x>y)?(printf("\n\n X is greater than Y")):(printf("\n\n Y is greater than X"));
    use smilie as ':'.....
     
  6. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    You can prevent smilies (which will be common in C/C++code) by clicking "Go Advanced" and checking the "Disable smilies in text" box....
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Nope its :(

    Or you can wrap the code tags around.
    Code:
    (x>y)?(printf("\n\n X is greater than Y")):(printf("\n\n Y is greater than X"));
     
  8. wrecker

    wrecker New Member

    Joined:
    Mar 12, 2007
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for suggestion. Was unaware of this. WOuld surely keep in mind while posting next time.....
    - Wrecker
     
  9. gjkalaj

    gjkalaj New Member

    Joined:
    May 2, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello everybody..
    Maybe this request is not related with this section but however I want to ask U if possibly somebody knows... and the question is:

    Its about the Graphs as data structures in C programming implementing with adjacency matrix or list or stack (same)

    I want to ask if someone knows how is the CODE or Algorithm for solving problem that is related with INTERSECTION OF TWO GRAPHS(I said as a data structure)

    If someone knows THNX
    If someone doesn know another THNX :))
     
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    gjkalaj, try creating a separate thread for the query with a suitable heading as that will make your query more visible and also help others when searching for something similar.
     
  11. sharma_atul13

    sharma_atul13 New Member

    Joined:
    Jul 16, 2007
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    liked the solution of wrecker as I knew this before with the use of Question operator
    but thanx for if statement solution
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice