Hey priya,
Ok let me analyse it once again...
keep this logic in mind...
1. if it is a post increment directly use the same value without
incrementing and then increment.
2. if it is a preincrement (increment a and then wait) or operand with no
operation then wait for its first operand to complete its operation. If
there are no operands or operand with no operators ahead it simply
increments in case of preincrement...

Direction of evaluation right to left

a=1
printf("%d %d ", ++a, a);
2nd rule applies for 2nd a , it waits for first operand to compelte its
operation...
So for first a 2nd rule applies for first a where no operands ahead and
preincrement which increases a value to 2 and uses it for printing...
So first prints 2 and then waiting second prints 2
output 2,2

printf("%d %d", a++, a);
2nd rule applies for 2nd a , it waits for first operand to compelte its
operation...
first operand using 1st rule uses a value as 2 and then increments it and
now waiting second prints 2
output 1,2

printf("%d %d", a , a++);

1st rule applies to 2nd a, it uses a and then increments it..
2nd a using second rule simply uses current value of a..
output 2,1


printf("%d %d", a, ++a);
2nd rule applies to 2nd a it simply increments a uses it..
1st a using 2nd rule uses only current a value...
output 2,2

printf("%d %d",++a,++a)
2nd rule for 2nd a increments a now wait for first operand...
first operand increment a and use it...
waiting 2nd a uses current a value
output 3,3

printf("%d %d",a++,++a)
2nd operand evaluates first increments a and waits for first...
1st uses a and then increments a to 3
waiting 2nd uses a..
output 2,3

printf("%d %d, ++a,a++)
2nd operand uses a and then increments
1st operand increments and then use..
so output 3,1

printf("%d %d", a++, a++)
2nd operand uses a and then increments
1st operand uses a and then increments
output 2,1 afterprintf a value contains 3

printf("%d %d %d", a++,++a,a)
same logic for last two operands except that now waiting has postponed till
1 st operand...
output 2,3,3

so your question

b=a+++++a
b=10
a=11
b=10 + ++a
a=12
b=10 + 12
b=22

first %d takes b value 22

3rd a increments a value to 13 waits for 2nd and 1st 'a' s
second a waits for first a
first a uses current a and then increments
second a uses current a
3rd a uses current a..
so output is 13,14,14.


It may be confusing...
Let me know if you are...
Kartheek


According to our discussion in first place i told %d takes a values from

On Sun, Jan 9, 2011 at 11:16 AM, priya mehta <priya.mehta...@gmail.com>wrote:

> ok but the output of
> int a=10,b;
> b=a++ + ++a;
> printf("%d,%d,%d,%d",b,a++,a,++a);
> is 22 13 14 14
> howz that then?
>
> On Sun, Jan 9, 2011 at 11:11 AM, kartheek muthyala <kartheek0...@gmail.com
> > wrote:
>
>> Yeah you might be knowing how the expression evaluators work using stack
>> right. printf also uses the same approach....
>>
>>
>> On Sun, Jan 9, 2011 at 11:06 AM, priya mehta <priya.mehta...@gmail.com>wrote:
>>
>>> @kartheek so does it use stack for that?
>>>
>>>
>>> On Sun, Jan 9, 2011 at 11:03 AM, priya mehta 
>>> <priya.mehta...@gmail.com>wrote:
>>>
>>>> ok
>>>> i got that
>>>>
>>>>   On Sun, Jan 9, 2011 at 11:01 AM, kartheek muthyala <
>>>> kartheek0...@gmail.com> wrote:
>>>>
>>>>> small correction printf evaluation starts from right to left.....
>>>>>
>>>>>
>>>>> On Sun, Jan 9, 2011 at 10:59 AM, kartheek muthyala <
>>>>> kartheek0...@gmail.com> wrote:
>>>>>
>>>>>> @priya,
>>>>>>
>>>>>> Generally printf evaluation starts from left to right....
>>>>>> so first a++ using post increments assign the value of 3rd %d to be 2
>>>>>> then a++gets evaluated , now a value is 3
>>>>>> 2nd %d takes a value as 3
>>>>>> 1st %d takes a value as 3
>>>>>>
>>>>>> if it is a preincrement like ++a in the third place
>>>>>> the output will be 3,3,3...
>>>>>>
>>>>>> got it i guess...
>>>>>>
>>>>>> Thanks,
>>>>>> Kartheek.
>>>>>>
>>>>>> On Sun, Jan 9, 2011 at 10:38 AM, priya mehta <
>>>>>> priya.mehta...@gmail.com> wrote:
>>>>>>
>>>>>>>  int a=2;
>>>>>>> printf("%d %d %d",a,a,a++);
>>>>>>> the output is 3 3 2
>>>>>>> can someone tell the logic behind this?
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "Algorithm Geeks" group.
>>>>>>> To post to this group, send email to algoge...@googlegroups.com.
>>>>>>> To unsubscribe from this group, send email to
>>>>>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>>>>>>> .
>>>>>>> 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 algoge...@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>>>>> .
>>>>> 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 algoge...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>>> .
>>> 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 algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> 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 algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to