Mar 15, 2022 at 4:05pm UTC
The code below is to test characteristics of a pointer array. It only has output in hex. I was expecting int/float or anything other than hex. What does it have/didn't have that is causing this?
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 48 49 50 51 52 53 54 55 56 57 58 59 60
// array_4.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
int x = 10, y = 12, z = 2;
int count = 1;
int *** a = new int **[x];
for (int i = 0; i < x; i++) {
// Allocate memory blocks for
// rows of each 2D array
a[i] = new int *[y];
for (int j = 0; j < y; j++) {
// Allocate memory blocks for
// columns of each 2D array
a[i][j] = new int [z];
}
}
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int k = 0; k < z; k++) {
// Assign values to the
// memory blocks created
a[i][j][0] = 99;
a[i][j][1] = 69;
k++;
}
}
}
std::cout << "Print matrix" << std::endl;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int k = 0; k < z-1; k++) {
std::cout << a[i][j][0] << std::endl;
std::cout << a[i][j][1] << std::endl;
}
cout << endl;
}
cout << endl;
}
std::cout << "working order:" << std::endl;
std::cout << "x'y' :" ;
int img_x = 0, img_y = 0;
std::cin >> img_x;
std::cin >> img_y;
std::cout << "point: img x: " << img_x << "y: " << img_y << a[img_x, img_y, 0]<< std::endl << a[img_x, img_y, 1] << std::endl;
}
Last edited on Mar 15, 2022 at 5:05pm UTC
Mar 15, 2022 at 4:34pm UTC
It doesn't compile, because you haven't declare i_x and i_y.
It spits out garbage because thats what you told to spit out with a[i_x, i_y, 0]
(these are 3-component c++ arrays, not Python's numpy arrays).
Mar 15, 2022 at 5:00pm UTC
Ok, I've reposted what was an error on my part. The same problem persists when running, hexadecimal output:
Input image point x,y to retrieve corresponding x'y' :2
2 point: img x: 2 y: 2000002CB239E32C0 000002CB239E3330
Last edited on Mar 15, 2022 at 5:07pm UTC