C ++ array 2d error

I'm trying to run a C ++ 2d array (pretty simple file) and it works, but an error appears at the end (at least I think it is a bug).

Code for array:

int myArray[10][10];
for (int i = 0; i <= 9; ++i){

    for (int t = 0; t <=9; ++t){

        myArray[i][t] = i+t; //This will give each element a value

    }

}

for (int i = 0; i <= 9; ++i){

    for (int t = 0; t <=9; ++t){

        cout << myArray[i][t] << "\n";

    }

      

this prints the array correctly but adds

"0x22fbb0"

at the end. What is it and why is it happening?

0


source to share


2 answers


The error is not in the code you posted. do you have another cout after?

0x22 ... looks like a memory address, so you might have a string that reads



cout <tyAggau;

somewhere.

+5


source


The code you showed is fine so far. The selected address is not printed from this part of your code. For this I can imagine two situations.

  • You accidentally typed myArray [i] or myArray and forgot to apply a different index. Since the value of the array is converted to the address of its first element, it causes the address to be printed.
  • You accidentally print cout as cout <cout. cout has an implicit conversion to a pointer type (it is used to check the state of sane for example in if(cout) { ... }

    ) and this will cause the address to be printed as well.


This could be a completely different situation. Can you paste the code that appears after two loops?

+6


source







All Articles