C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 12)
12.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class PowerFinder
{
public:
void Power(int x = 1, int y = 1)
{
int P = 1, i = 1;
while(++i <= y)
{
P *= x;
}
cout<< P << endl;
}
};
int main()
{
PowerFinder FP;
FP.Power(2, 6);
return 0;
}
Discussion:
1 comments Page 1 of 1.
Anandkumar said:
1 decade ago
In that function x=2, y=6 after the function power is calling.
In while loop it will execute up to I get value of 6.
So while loop execute 5 times. So that p*=x value will become 32. {2*2*2*2*2 = 32}
In while loop it will execute up to I get value of 6.
So while loop execute 5 times. So that p*=x value will become 32. {2*2*2*2*2 = 32}
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers