an array outputting hex when i need dec

Ok: first post ever

I made a multidimensional array with 2 indices and it worked great. Data comming out exactly as expected.

Then I took the same array and added a third indices, however when I run the program all my values come out just fine with the exception that they are in hexadecimal.

I'm not at home on the machine with the problem on it. But if needed I can put up a cut/paste as soon as I get home.

All I want to know is why is it in hexadecimal and how can I force into decimal.


Thanks for the help ahead of time, I spent two days in books and on google etc looking this up and finally decided it was time for help.
It would be very hard to guess at an answer, so go ahead.. Cut 'n Paste please.
code for first is as follows:

#include <iostream>

using namespace std;

int main()
{
int arr[3] [3] = {{1,2,3} , {4,5,14}} ;
cout<<"arr[0][0] contains"<<arr[0][0]<<endl;
cout<<"arr[0][1] contains"<<arr[0][1]<<endl;
cout<<"arr[0][2] contains"<<arr[0][2]<<endl;

cout<<"arr[1][0] contains"<<arr[1][0]<<endl;
cout<<"arr[1][1] contains"<<arr[1][1]<<endl;
cout<<"arr[1][2] contains"<<arr[1][2]<<endl;

above this line is code for first problem which compiles and gives me whats in the array in decimals

below this line is same thing with an added (indices i think its called)
whatever is in the array comes out hexadecimal.


#include <iostream>

using namespace std;

int main()
{
int arr[3] [3] [3]= {{1,2,3} , {4,5,14} , {15,16,17}};
cout<<"arr[0][0] contains"<<arr[0][0]<<endl;
cout<<"arr[0][1] contains"<<arr[0][1]<<endl;
cout<<"arr[0][2] contains"<<arr[0][2]<<endl;

cout<<"arr[1][0] contains"<<arr[1][0]<<endl;
cout<<"arr[1][1] contains"<<arr[1][1]<<endl;
cout<<"arr[1][2] contains"<<arr[1][2]<<endl;

cout<<"arr[2][0] contains"<<arr[2][0]<<endl;
cout<<"arr[2][1] contains"<<arr[2][1]<<endl;
cout<<"arr[2][2] contains"<<arr[2][2]<<endl;


return 5;
}
With a 3 dimensional array, you need 3 brackets to access the values properly, otherwise the compiler thinks your accessing a pointer, explaining the hex.

 
arr[x][y]


should be:
 
arr[x][y][z]
int arr[3] [3] [3]= {{1,2,3} , {4,5,14} , {15,16,17}};
is [x][y][z] isnt it?
forgive me if I'm not gettin it, its not making sence or giving me decimal answers that way.
Your explanation I get about it thinking its accessing a pointer but with
[3][3][3] that seems to be what your saying. (i compiled it again just to make sure.) and it still gives hex.
Last edited on
No, it thinks its a pointer when you access a 3d array using only 2 sets of brackets, which is what your doing in your cout statements. The reason its outputting actual numbers instead of addresses is because of how arrays work under the hood.
thanks I think Ill table that till I get a little more experience in arrays.......turns out what I was trying to do is very rare.

One last question can I force a decimal out out in some manner?
Yes you can, using manipulators. http://www.cplusplus.com/reference/iostream/manipulators/dec/ is the one you want.
Topic archived. No new replies allowed.