Get pointers instead of numbers

I am writing a code for this http://www.programmr.com/challenges/matrix-multiplication-0 programmr challange and can't find the error in my code. I soppose the compiler is showing me somehow pointers instead of numbers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  int main()
{
    int arr[3][3]={0};
     int arr1[3][3]={0};
     int arr2[3][3]={0};


     for(int i = 0; i < 3; i++) {
       for(int j = 0; j <3; j++) {
          cout<<"Matrix 1st ["<<i<<"]["<<j<<"]:\n";
          cin>>arr[i][j];
        }
       }

     for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
          cout<<"Matrix 2nd ["<<i<<"]["<<j<<"]:\n";
          cin>>arr1[i][j];
        }
       }

  //write your logic here
  
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                arr2[i][j] += arr[i][k] * arr1[k][j];
            }
        }
    }

  //end


  cout<<"Multiply of both matrix:\n";

  for(int i = 0; i < 3; i++)
  {
     for(int j = 0; j < 3; j++)
      {
          cout<<arr2[i,j]<<" ";
      }
     cout<<"\n";
  }

return 0;
}
Line 41 is not right cout << arr2[i,j] << " ";
I don't know what would be wrong on line 41. I pasted your code and it still doesn't work
Hey @Fajsdie, if what you mean is that you copy-pasted what Thomas1965 wrote in the quote, then it's just that he says it's wrong to write that.
If that's the case, then try writing arr2[i][j]
 
cout<<arr2[i][j]<<" ";

, because it's a 2-dimensional array, not one with 2 parameters inside the square brackets (which I don't know if it does exist at all).
If it's not the case, then let me look at the code thoroughly (if necessary). In the meantime, could you tell me what line your compiler says the error is on? And if you could tell me what it says exactly, then that would be perfect.
Also if it's not compiler error (that's what I understand from "showing me pointers"), then could you say exactly what it is? Maybe I might be able to help if I know exactly what's going on.
Compare this on line 41:
 
arr2[i,j]
with this on line 27
 
arr2[i][j]


Technically, what happens is that the expression i,j is evaluated. It contains the comma operator (see tutorial) and the resulting value is simply j.

Hence line 41 is equivalent to
 
cout << arr2[j] << " ";


There is something missing - the second pair of [ ]



See Comma operator ( , )
http://www.cplusplus.com/doc/tutorial/operators/


Thank you,

I haven't seen this mistake. There is no compiler error and what the programm is showing are those weird numbers:

0x6afea8 0x6afeb4 0x6afec0
0x6afea8 0x6afeb4 0x6afec0
0x6afea8 0x6afeb4 0x6afec0
There is no compiler error

It doesn't give an error, since the code is valid.

However it does give a warning (depending on compiler and settings).
[Warning] left operand of comma operator has no effect [-Wunused-value]


If you supply only one subscript for a 2D array, the result is a 1D array.
Say for example you do this:
1
2
3
4
    int array[5] = {2, 3, 6, 8, 10};
    
    cout << array[3] << '\n';
    cout << array    << '\n';

The first cout will output the value 8. The second will output the address of the array.


If you use g++ compiler, you could use the compiler settings to get as many warnings/error message as possible (messages from the compiler are there to help you avoid such accidental mistakes).
-std=c++11 -Wextra -Wall -pedantic
Topic archived. No new replies allowed.