659 views
1 1 vote
If f is a float and n an int, then the expression

(n > 0) ? f : n

is of type float regardless of whether n is positive.

Why?

1 Answer

0 0 votes
Information loss is a major concern. For an operator with operands of different types the operands are converted to a common type, generally from a narrower to a wider operand without losing information. In simple terms more number of bits to represent the information.

"If f is a float and n an int, then the expression
(n > 0) ? f : n
is of type float regardless of whether n is positive."

Here the n gets converted to the type float and regardless of what n is the result is of type float.
One can read rules of type conversion from the standard. ( http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf  , page 129)
Position:
Show:

Related questions

0 0 votes
1 answers 1 answer
937
937 views
srestha asked Aug 9, 2018
937 views
Lines from Dennis Ritchie1)The variables named in a structure are called members. A structure member or tag and an ordinary (i.e., non-member) variable can have the same ...
1 1 vote
0 0 answers
652
652 views
himanshu19 asked Aug 4, 2018
652 views
Hi friends, In the following program when I am using '-' in the expression "ndigit[c - '0'];" I am getting correct result but wen I am using + then I am not getting the ...
0 0 votes
0 0 answers
980
980 views
Akhilesh Singla asked Mar 17, 2018
980 views
Hi. I gave GATE 2018 by dropping the year and I was able to solve most of the GATE questions on programming. Before GATE I didn't have any interest in programming. But no...
1 1 vote
0 0 answers
483
483 views
shaurya vardhan asked Oct 2, 2017
483 views
Ques) Write a program to copy its input to its output, replacing each tab by \t , each backspace by \b , and each backslash by \\ . This makes tabs and backspaces visible...