Your array contains char
elements, not int
elements.
If you look as an ASCII table, like https://www.asciitable.com, you will see that ASCII code 35 is for character '#'
, ASCII code 47 is for character '/'
, and ASCII codes 15 and 23 are for non-printable characters.
So, printing 15
/23
as char
values won't display anything meaningful, and printing 35
/47
as char
values will display as #/
.
To do what you are attempting, you need to print out the values as integers, not as characters, eg:
#include <iostream>
int main()
{
int arr[2][2] = { {15, 23}, {35, 47} }; // <-- int, not char!
for(int i = 0; i < 2; ++i){
for (int j = 0; j < 2; ++j){
std::cout << arr[i][j] << ' ';
}
std::cout << std::endl;
}
}
On the other hand, if you actually need a char[]
array, then you will have to convert the values when printing them, eg:
#include <iostream>
int main()
{
char arr[2][2] = { {15, 23}, {35, 47} };
for(int i = 0; i < 2; ++i){
for (int j = 0; j < 2; ++j){
std::cout << static_cast<int>(arr[i][j]) << ' ';
// or:
// std::cout << +arr[i][j] << ' ';
}
std::cout << std::endl;
}
}