You are here:

C/programming

Advertisement


Question
main()
{
int a=5,*b=&a;
printf("%d",a*b);
}

will u plz tell me the outout of this program with reason.

Answer
Hi 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  

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.