well I dint expect that value for y:)!! thot it wud be 16 again..but since u
ask me to guess i wud say that as we go left to right , the first
preincrement causes x to be 4 and the ones within the bracket cos it to be 5
and then 6:Now first addition within the braces is 6+6=12 and then this is
added to 6(since x was already incremented earlier) to be 18..hey it is a
totally wild guess
what is the right approach here?:)



On Mon, Jul 25, 2011 at 12:10 PM, sagar pareek <[email protected]>wrote:

> yeah u are right   :)
> try this one:-
>
> x=3;
> y=++x + (++x + ++x);
>
> answer is y=18   guess why ?
>
>
> On Mon, Jul 25, 2011 at 2:27 PM, Arun Vishwanathan <[email protected]
> > wrote:
>
>> thanks sagar!
>> so just to confirm ,what i get from above is that the x value before the
>> first addition is first updated from 3 to 5( due to 2 pre increments) and
>> then 5 and  5 is added to make the 10.This is then added to 6( as before the
>> second addition x is updated again)
>>
>> if y = x++ + ++x + x++
>> then will the value seem like for the first addition(x++ + ++x ) as
>> 4+4?(since the single pre increment increases the value of x by 1) ,and then
>> for the next addition it would be 8+4(since post increment here so x doesnt
>> change)?finally the value of x is 6?
>> pls correct me if wrong ...
>>
>>
>>
>>
>> On Mon, Jul 25, 2011 at 10:21 AM, sagar pareek <[email protected]>wrote:
>>
>>> Well its not like that
>>> first u have x=3;
>>> now u have to do
>>> y=++x + ++x + ++X;
>>> before doing first addition
>>> y=(++x + ++x) + ++x;
>>>        ^          ^
>>>
>>> above spotted x will increase , before their addition
>>> and then
>>> y= 5+5 + ++x;
>>> now
>>> y=10+ 6
>>> y=16;
>>>
>>> hope u now get it :)
>>>
>>>
>>> On Sun, Jul 24, 2011 at 2:30 PM, Arun Vishwanathan <
>>> [email protected]> wrote:
>>>
>>>> *x= 3 initially
>>>>
>>>>
>>>> On Sun, Jul 24, 2011 at 11:00 AM, Arun Vishwanathan <
>>>> [email protected]> wrote:
>>>>
>>>>> if that is the case as u say, then wont it be 3+ 4+ 5 when x +3
>>>>> initially?..and then x increments by one later due to the single post
>>>>> increment
>>>>>
>>>>>
>>>>> On Sun, Jul 24, 2011 at 10:15 AM, sagar pareek 
>>>>> <[email protected]>wrote:
>>>>>
>>>>>> nope compiler read it from left to right
>>>>>>
>>>>>>
>>>>>> On Sun, Jul 24, 2011 at 12:05 AM, Arun Vishwanathan <
>>>>>> [email protected]> wrote:
>>>>>>
>>>>>>> @sagar: if what u said previously holds as in when u say y=x++ + ++x
>>>>>>> is evaluated as 4+4 since ++x results in 4 and 4 is used in x++ too (cos
>>>>>>> post increment increments x later) then for y=x++ + ++x + ++x with x
>>>>>>> beginning as 3 shud the expression not be evaluated as 5+5+4( from rhs 
>>>>>>> ++x
>>>>>>> does a 3 to 4 and another ++x does 4 to 5 and 5 is used in x++) .later x
>>>>>>> becomes 6 ?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Sat, Jul 23, 2011 at 2:39 PM, sagar pareek <[email protected]
>>>>>>> > wrote:
>>>>>>>
>>>>>>>> sorry for above...typo mistake :-
>>>>>>>>
>>>>>>>>  yup
>>>>>>>> but what about this
>>>>>>>> x=3;
>>>>>>>>  y= x++ + ++x + ++x; // it is executed as:-
>>>>>>>>
>>>>>>>> during first addition, increase the value of x, now first addition
>>>>>>>> will be 4+4 + ++x;
>>>>>>>> now for second addition it will be like
>>>>>>>> 8+5
>>>>>>>> hence final value of y=13;
>>>>>>>> do it by urself
>>>>>>>>
>>>>>>>> On Sat, Jul 23, 2011 at 6:09 PM, sagar pareek <
>>>>>>>> [email protected]> wrote:
>>>>>>>>
>>>>>>>>> yup
>>>>>>>>> but what about this
>>>>>>>>> x=4;
>>>>>>>>> y= x++ + ++x + ++x; // it is executed as:-
>>>>>>>>>
>>>>>>>>> during first addition, increase the value of x, now first addition
>>>>>>>>> will be 4+4 + ++x;
>>>>>>>>> now for second addition it will be like
>>>>>>>>> 8+5
>>>>>>>>> hence final value of y=13;
>>>>>>>>> do it by urself
>>>>>>>>>
>>>>>>>>> On Sat, Jul 23, 2011 at 2:54 PM, shady <[email protected]> wrote:
>>>>>>>>>
>>>>>>>>>> @sagar
>>>>>>>>>> would it get evaluated like this ?
>>>>>>>>>> supposing x = 3;
>>>>>>>>>>
>>>>>>>>>> y = x++ + ++x; becomes y = (x=x+1) + (x=x+1);
>>>>>>>>>> then x=x+1;
>>>>>>>>>>
>>>>>>>>>> so x = 5, y = 8;
>>>>>>>>>>
>>>>>>>>>> On Sat, Jul 23, 2011 at 2:48 PM, sagar pareek <
>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>
>>>>>>>>>>> @Venga
>>>>>>>>>>> if u are doing this
>>>>>>>>>>> y= x++ + ++x; //x=3
>>>>>>>>>>> then it would be
>>>>>>>>>>> like that :-
>>>>>>>>>>> ++x; //x=4
>>>>>>>>>>> y=x+x;
>>>>>>>>>>> x++;
>>>>>>>>>>>
>>>>>>>>>>> i thing this is sufficient  :)
>>>>>>>>>>>
>>>>>>>>>>> On Sat, Jul 23, 2011 at 1:20 PM, Interstellar Overdrive <
>>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> The expression y = x++ + x++ + ++y;  is not a valid one. The
>>>>>>>>>>>> result is compiler dependent
>>>>>>>>>>>> Read this for reference :http://c-faq.com/expr/seqpoints.html
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>>>> Google Groups "Algorithm Geeks" group.
>>>>>>>>>>>> To view this discussion on the web visit
>>>>>>>>>>>> https://groups.google.com/d/msg/algogeeks/-/-DWyCxlftwgJ.
>>>>>>>>>>>>
>>>>>>>>>>>> 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.
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> **Regards
>>>>>>>>>>> SAGAR PAREEK
>>>>>>>>>>> COMPUTER SCIENCE AND ENGINEERING
>>>>>>>>>>> NIT ALLAHABAD
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> 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.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> **Regards
>>>>>>>>> SAGAR PAREEK
>>>>>>>>> COMPUTER SCIENCE AND ENGINEERING
>>>>>>>>> NIT ALLAHABAD
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> **Regards
>>>>>>>> SAGAR PAREEK
>>>>>>>> COMPUTER SCIENCE AND ENGINEERING
>>>>>>>> NIT ALLAHABAD
>>>>>>>>
>>>>>>>>   --
>>>>>>>> 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.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>  Arun Vish
>>>>>>> Graduate Student
>>>>>>> Department of Computer Science
>>>>>>> University of Southern California
>>>>>>>
>>>>>>> --
>>>>>>> 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.
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> **Regards
>>>>>> SAGAR PAREEK
>>>>>> COMPUTER SCIENCE AND ENGINEERING
>>>>>> NIT ALLAHABAD
>>>>>>
>>>>>> --
>>>>>> 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.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>  Arun Vish
>>>>> Graduate Student
>>>>> Department of Computer Science
>>>>> University of Southern California
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>>  Arun Vish
>>>> Graduate Student
>>>> Department of Computer Science
>>>> University of Southern California
>>>>
>>>> --
>>>> 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.
>>>>
>>>
>>>
>>>
>>> --
>>> **Regards
>>> SAGAR PAREEK
>>> COMPUTER SCIENCE AND ENGINEERING
>>> NIT ALLAHABAD
>>>
>>> --
>>> 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.
>>
>
>
>
> --
> **Regards
> SAGAR PAREEK
> COMPUTER SCIENCE AND ENGINEERING
> NIT ALLAHABAD
>
> --
> 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.
>



-- 
 Arun Vish
Graduate Student
Department of Computer Science
University of Southern California

-- 
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