C++ Programming - Functions - Discussion

Discussion Forum : Functions - Programs (Q.No. 27)
27.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class BixArray
{
    int Matrix[3][3]; 
    public:
    BixArray()
    {
        for(int i = 0; i<3; i++)
           for(int j = 0; j < 3; j++) 
              Matrix[j][i] = i + j; 
    }
    void Display(void)
    {
        for(int i = 0; i < 3; i++)
           for(int j = 0; j < 3; j++) 
              cout<< Matrix[j][i] << " "; 
    } 
}; 
int main()
{
    BixArray objBix;
    objBix.Display();
    return 0; 
}
The program will display the output 4 3 2 3 2 1 2 1 0.
The program will display the output 0 1 2 1 2 3 2 3 4.
The program will display the output 9 garbage values.
The program will report error on compilation.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
2 comments Page 1 of 1.

Karthick said:   3 years ago
Thanks @Chanchla.

Chanchla said:   9 years ago
1)for the outer loop 1st pass value of i=0
value of j=0,1,2
i+j=0+0=0; 0+1=1; 0+2=2
After execution of inner loop out is 012

2)for the 2nd pass of outer loop value of i=1;
j=0,1,2
i+j=1+0=1; 1+1=2; 1+2=3
after execution of inner loop out is 1,2,3

3)for the 3rd pass of outer loop value of i=2;
j=0,1,2
i+j=2+0=2; 2+1=3; 2+2=4
after execution of inner loop out is 2,3,4

The condition false exit from the loop.
Output is 0,1,2,1,2,3,2,3,4.

Post your comments here:

Your comments will be displayed after verification.