if then else trinary operator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • namrata1980
    New Member
    • Mar 2007
    • 1

    if then else trinary operator

    Hello

    please explain the following:-

    Say if
    int i,sign;
    double atof(char s[ ]);
    has been declared and then there is statement
    sign=(s[i]=='-' ) ? -1:1;
    [/U]

    Thanks in advance........ ..
    Last edited by namrata1980; Apr 10 '07, 11:48 AM. Reason: ---
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Hi,
    the code u have put is a ternary operator.
    sign=(s[i]=='-' ) ? -1:1;
    If user has entered a negative value the the value of sign will be -1 or else 1

    Thanks
    Raghuram

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Did you try putting that into a compiler?

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        In the future please follow the following rules from the FAQ:

        Using a good, clear thread title is important. The reasons for this are:

        * We want this site to grow, many of our new members find the site using a search engine, by using a good thread title you will help us grow the site by helping us get better search engine rankings.
        * Using a good title will benefit you too because other members of the forum will be less likely to skip over your thread and it allows the experts to quickly scan through the forum for questions they know the answer to.
        * If the threads are well titled it allows other users to easily see if there have been any threads that could be relevant to their own current problem.
        * It is in everybody's best interests to post properly titled threads as the more time the moderators have to spend on managing titles the less time they have available to give answers to the questions posed.

        Comment

        Working...