Tuesday 26 March 2013

*f2+=*f2+=a+=2.5;


    main()
{
         int a=2,*f1,*f2;
    f1=f2=&a;
         *f2+=*f2+=a+=2.5;
    printf("\n%d %d %d",a,*f1,*f2);
}
Answer:
16 16 16
Explanation:
f1 and f2 both refer to the same memory location a. So changes through f1 and f2 ultimately affects only the value of a.

Blog Author: Vijay Kumar

2 comments:

  1. Replies
    1. *f2+=*f2+=a+=2.5;

      *f2=*f2+(*f2=*f2+(a=a+2.5));

      *f2=*f2+(*f2=*f2+(a=2+2)); // .5 is truncated

      *f2=*f2+(*f2=*f2+(4));

      *f2=*f2+(*f2=4+4); // f2 is assigned a's address and a's value is 4 now.

      *f2=8+8;




      Delete