#include<stdio.h>
main()
{
int i=1;
printf("\n%d%d, i<<=1%2);
return 0;
}
In the above program the output is 2 as expected .
now since
#include<stdio.h>
main()
{
int i=1;
printf("\n%d%d ",i<<=2,i<<=1%2);
return 0;
}
Now since we are introducing an another statement which modifies i in the
same line , the previous value of i gets affected and changes to the new
value provided by the first i<<=2
So above o/p will be 8 8
though i<<=1%2 is 2 initially
it gets affected by i<<=2 and so value changes to 8 of both i's
Hope this is clear ...
On Mon, Jul 25, 2011 at 11:06 PM, aditi garg <[email protected]>wrote:
> Can u plz elaborate...im not able to understand...
>
> On Mon, Jul 25, 2011 at 11:04 PM, rajeev bharshetty
> <[email protected]>wrote:
>
>> @sameer I think that is right
>>
>>
>> On Mon, Jul 25, 2011 at 11:02 PM, [email protected] <
>> [email protected]> wrote:
>>
>>> its because of side effect where value of i is getting changed twice in a
>>> single line.
>>> correct me if i am wrong :)
>>>
>>> *Muthuraj R.
>>> 4TH Year BE.**
>>> Information Science Dept*
>>> *PESIT, Bengaluru .
>>> *
>>>
>>>
>>>
>>>
>>> On Mon, Jul 25, 2011 at 11:01 PM, geek forgeek <[email protected]>wrote:
>>>
>>>> y not the output is 3 2 coz on right to left evaluation of printf i
>>>> shud be left shifted by 1 bit wgich shud make it 2 ??
>>>>
>>>>
>>>> On Mon, Jul 25, 2011 at 10:28 AM, [email protected] <
>>>> [email protected]> wrote:
>>>>
>>>>> yeah output
>>>>> 0
>>>>> 1 1
>>>>> *is dis because of side effect? *
>>>>> * *
>>>>> *
>>>>> *
>>>>> *Muthuraj R.
>>>>> 4TH Year BE.**
>>>>> Information Science Dept*
>>>>> *PESIT, Bengaluru .
>>>>> *
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Mon, Jul 25, 2011 at 10:49 PM, Deoki Nandan <[email protected]>wrote:
>>>>>
>>>>>> run on gcc compiler it would be
>>>>>> 0
>>>>>> 1 1
>>>>>>
>>>>>>
>>>>>> On Mon, Jul 25, 2011 at 10:35 PM, geek forgeek <[email protected]
>>>>>> > wrote:
>>>>>>
>>>>>>> 1.
>>>>>>> #include<stdio.h>
>>>>>>> main()
>>>>>>> {
>>>>>>> int i=1;
>>>>>>> printf("\n%d",i^=1%2);
>>>>>>> printf("\n%d %d",i^=1%2,i<<=1%2);
>>>>>>> return 0;
>>>>>>> }
>>>>>>>
>>>>>>> output 3 3
>>>>>>> hey shudnt the output be 3 2
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> 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.
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> **With Regards
>>>>>> Deoki Nandan Vishwakarma
>>>>>>
>>>>>> *
>>>>>> *
>>>>>>
>>>>>> --
>>>>>> 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.
>>>>
>>>
>>> --
>>> 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
>> Rajeev N B <http://www.opensourcemania.co.cc>
>>
>>
>> --
>> 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.
>>
>
>
>
> --
> Aditi Garg
> Undergraduate Student
> Electronics & Communication Divison
> NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
> Sector 3, Dwarka
> New Delhi
>
> 9718388816
>
> --
> 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
Rajeev N B <http://www.opensourcemania.co.cc>
--
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.