(A) i = 20; i++;
(B) for (i = 0; i<20; i++) { }
(C) a = i++;
(D) while (i++ = 20) cout <<i;
Ans: A
Why ???
wen u change i++ to ++i, C, D will get effected.
C - i++ increments i, bt it returns the original value. where as ++i will
increment i nd will return the incremented value.
so, a = i++ -> 20
a = ++i -> 21
D. -- i++ returns a const int value, so its not a lvalue nd hence cant be on
lhs of =
++i returns a reference of int object, nd so is an lvalue nd hence
can be on lhs of =., so if u change the i++ to ++i in this st, it will
compile.
A, B - here the increment operator is a separate st, so whether its pre/post
increment doesn't matter, any st after this will ve the incremented i.
On Tue, Aug 30, 2011 at 11:51 AM, nidhi jain <[email protected]>wrote:
>
>
> yes, D vl give an error ,as increment operator cannot be used as lvalue for
> assignment.
>
> NIDHI JAIN
> INFORMATION TECHNOLOGY(FINAL YEAR)
> NIT,DURGAPUR
>
> --
> 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.