@sengar: sorry dude...i got his doubt.Though my explanation was correct. I think now everybody's doubt is clear.By the way thanx for correcting me.
On Fri, Jun 8, 2012 at 11:48 AM, sengar.mahi <[email protected]> wrote: > @naveen :read the his doubt properly...he was expecting 5 10 15 but was > getting 8 32 96...and dats the correction required which i made > > > On Fri, Jun 8, 2012 at 8:08 AM, Navin Kumar <[email protected]>wrote: > >> @Mahendra: for ur above code with t=(a<<2)+a o/p will be 5,10, 15 as i >> explained above. without bracket answer will be 8 , 32 and 96 because + >> precedence is higher than <<. >> >> >> On Fri, Jun 8, 2012 at 7:31 AM, Mahendra Sengar <[email protected]>wrote: >> >>> Cracked it...i guess precedence of + is more than << >>> so >>> use t=(a<<2)+a; >>> >>> I checked, its giving proper output now !!! >>> >>> >>> On Friday, June 8, 2012 5:46:09 AM UTC+5:30, algo lover wrote: >>>> >>>> The following is a simple C program which tries to multiply an integer >>>> by 5 using the bitwise operations. But it doesn't do so. Explain the reason >>>> for the wrong behavior of the program. >>>> >>>> #include <stdio.h> >>>> #define PrintInt(expr) printf("%s : %d\n",#expr,(expr)) >>>> *int* FiveTimes(*int* a) >>>> { >>>> *int* t; >>>> >>>> >>>> >>>> t *=* a*<<*2 *+* a; >>>> >>>> >>>> >>>> *return* t; >>>> } >>>> >>>> *int* main() >>>> { >>>> *int* a *=* 1, b *=* 2,c *=* 3; >>>> >>>> >>>> >>>> PrintInt(FiveTimes(a)); >>>> PrintInt(FiveTimes(b)); >>>> >>>> >>>> >>>> PrintInt(FiveTimes(c)); >>>> *return* 0; >>>> } >>>> >>>> -- >>> 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/-/7CNEyeGuUzEJ. >>> >>> 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.
