C++ Programming - References - Discussion
Discussion Forum : References - Programs (Q.No. 15)
15.
Which of the following statement is correct about the program given below?
#include<iostream.h>
int BixFunction(int m)
{
m *= m;
return((10)*(m /= m));
}
int main()
{
int c = 9, *d = &c, e;
int &z = e;
e = BixFunction(c-- % 3 ? ++*d :(*d *= *d));
z = z + e / 10;
cout<< c << " " << e;
return 0;
}
Discussion:
6 comments Page 1 of 1.
Chetan said:
10 years ago
(*d *= *d) // This is where c=64.
m*= m; // m=4096.
Return ((10)*(m /= m)) ; //returns 10.
z = z + e/10; //here e=10, z=10. z+(e/10) = 11.
m*= m; // m=4096.
Return ((10)*(m /= m)) ; //returns 10.
z = z + e/10; //here e=10, z=10. z+(e/10) = 11.
(1)
Pavithra said:
7 years ago
How z & e both are 10? Please explain.
(1)
Ayush said:
1 decade ago
Please tell how c is 64?
It can be 64 only when both conditions are satisfied ie c--%3 is true as well as false.
My doubt is how can this line code can assume c to be 9 till ':' sign and 8 after (:)this sign.
It can be 64 only when both conditions are satisfied ie c--%3 is true as well as false.
My doubt is how can this line code can assume c to be 9 till ':' sign and 8 after (:)this sign.
Anu said:
10 years ago
c is post-decrement, so (c--%3) is evaluated as (c%3). This is equal to 0, so the false condition has to be executed.
But after the (c%3) is done, c is decremented (c--) , before the false condition is evaluated.
But after the (c%3) is done, c is decremented (c--) , before the false condition is evaluated.
Vishal Singh said:
7 years ago
int &z = e; <- this statement created a reference of e as z.
Priyanka said:
7 years ago
Thanks @Chetan.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers