C/programming
Expert: Prince M. Premnath - 4/8/2010
Questionmain()
{
int a=5,*b=&a;
printf("%d",a*b);
}
will u plz tell me the outout of this program with reason.
AnswerHi Dear anshul !
Code what you have posted would sure throw error . since the pointer has been used illegally , you can make the above programme valid just bu putting another '*' between a*b
say printf ("%d" , a**b);
the above statement would bring you the result 25. since the expression a**b will be replaced with 5*5, take a look at the above conversion
'*' represents value at the address of
>>a**b;
>>5**b;
>>5*(*b); /* replace the '*' equivalent
>>5*(value at the address of 'b')
>> 5* 5; since the value pointed by 'b' is 5
and now the result is 25.
with your programme say >> printf("%d",a*b);
the above expression will be tried to parse as the method given above
results with 5(*b); which cannot form an expresson so throws error !
Hope this would have helped you. if not please get back to me :)
Thanks and Regards
Prince M. Premnath