CPPForSchool.com: User Defined Function Set 1: Assignment 11

11. Write the output of the following program:       

#include <iostream>
using namespace std;

int func(int &x, int y = 10)
{
    if (x % y == 0)
        return ++x;
    else 
        return y--;
}

int main()
{
    int p = 20, q = 23;

    q = func(p, q);
    cout << p << " " << " " << q << endl;
    
    p = func (q);
    cout << p << " " << " " << q << endl;

    q = func (p);
    cout << p << " " << " " << q << endl;
    
    return 0;
}

-----------------------------------------------

20  23
10  23
11  11



Comments

Popular posts from this blog

CPPForSchool.com: Variable, Operator & Expression Set 1: Assignment 9

CPPForSchool.com: Array - Single Dimension Set 1 Assignment 6

CPPForSchool.com: Variable, Operator & Expression Set 1: Assignment 8