There's nothing to do with the type of "A String".
The reason for which the first code gives compilation error is: operator
(<<) has higher precedence than ternary operator (?:) so, without braces
your are actually messing up the parsing of "cout << << << "stream.

* cout << test ? "A String" : 0 << endl;    *

consider removing the last "*<<endl*". It shall give no compilation error.

* cout << test ? "A String" : 0;* // this compiles and runs fine with my
compiler(g++ 4.5), but as *cout << test* will take precedence, there is no
point of putting a ternary operator there, unless you use braces, of course.


In teh second case however, reason given is valid:
 i.e. return type of ternary operator is determined by "A String" and the
expression 0 will be taken as address of a string location. Hence, there is
no guarantee of output.


On 31 October 2012 19:52, rahul sharma <[email protected]> wrote:

> plz read carefully
>
>
> On Wed, Oct 31, 2012 at 10:18 AM, Tamanna Afroze <[email protected]>wrote:
>
>> sorry for my last post, i didn't look carefully at the code. I think
>> without bracket the ternary expression is incomplete, that's why; first
>> code doesn't compile correctly.
>>
>>
>>
>> On Wed, Oct 31, 2012 at 9:51 AM, Tamanna Afroze <[email protected]>wrote:
>>
>>> both codes are same. Where is the difference?
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to