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;
}
The program will print the output 12.
The program will print the output 16.
The program will print the output 32.
The program will print the output 36.
The program will execute infinite time.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
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}
(1)

Post your comments here:

Your comments will be displayed after verification.