Showing posts with label Operator Precedence. Show all posts
Showing posts with label Operator Precedence. Show all posts

Wednesday, 17 February 2010

What is the output of this tricky program?

Interesting problem from C Programming tricks:



//Program tested on Microsoft Visual Studio 2008 - Zahid Ghadialy
#include<iostream>

using namespace
std;

int
main()
{

int
a=2,*f1,*f2;
f1=f2=&a;
*
f2+=*f2+=a+=2.5;
*
f1+=*f1+=a+=2.5;
cout<<"a = "<<a<<" *f1 = "<<*f1<<" *f2 = "<<*f2<<endl;

return
0;
}






What is the final value of a, *f1 and *f2. Choose one from below:
a) 18,18,18
b) 10,10,10
c) 72,72,72
d) 64,64,64
e) 26,26,26

The answer is...
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.