@Antony
res1=++a + ++a + ++a;
Well it depends on the compiler but i know how gcc works :)
from left to right it will first do addition of first two 'a'
before addition it will increment the value of a by two cos of two pre
increments.
then resulting addition will then be added to the incremented value of last
'a';
step wise step it will be :-
(++a + ++a) + ++a; //a=5
(7 + 7) + ++a; //a=7
14 + 8; //a=8
22;
for multiplication it will skip the addition a's as:-
++b + ++b*10 + ++b*100; //b=5
now from left to right reach to rightmost *
as
++b + ++b*10 + ++b*100;
^ ^
increment only ^ b's
now
++b + ++b*10 + 7*100;
^
now increase ^ b also
as
8 + 8*10 + 700
788
try different combinations also like
a=5;
++a + (++a + ++a); // this give answer=24 :)
On Sat, Jul 16, 2011 at 2:24 PM, sagar pareek <[email protected]> wrote:
> tell me your output pls
>
>
> On Sat, Jul 16, 2011 at 2:19 PM, sagar pareek <[email protected]>wrote:
>
>> and o/p is "%#s Zi" not "%s Zi"
>>
>>
>> On Sat, Jul 16, 2011 at 2:18 PM, sagar pareek <[email protected]>wrote:
>>
>>> @Kamakhsi
>>> In my ubuntu gcc this o/p is coming with warning of undefined "%#" :)
>>>
>>> On Sat, Jul 16, 2011 at 5:43 AM, sukhmeet singh
>>> <[email protected]>wrote:
>>>
>>>> @Anatony
>>>> the output will be compiler dependent
>>>> res1 is not defined .. as C don't allow to change the value of a
>>>> variable more than once between a sequence point..
>>>> A sequence point occur while assigning a value , calling a function or
>>>> returning from it..
>>>> Hence both res1 and res2 would give arbitary results..
>>>>
>>>> On Sat, Jul 16, 2011 at 1:45 AM, Antony Kotre <[email protected]>wrote:
>>>>
>>>>> can any tell and explain the output of following code
>>>>>
>>>>> #include<stdio.h>
>>>>> main()
>>>>> { int a =5, b=5;
>>>>> int res1=(++a)+(++a)+(++a);
>>>>> int res2=(++b)+(++b)*10+(++b)*100;
>>>>>
>>>>> printf("%d\n%d\n",res1,res2);
>>>>> }
>>>>>
>>>>> --
>>>>> 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
>>
>>
>
>
> --
> **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.