0

Original Problem
I have an existing 2D array that is already filled with data for a matrix. I also have a structure that has a pointer looking like this double ** pointer.

That being said. Here's a miniature version of the problem

#include <stdio.h>

int main (){
	int stuff [2][2];
	stuff[0][0] = 1;
	stuff[0][1] = 2;
	stuff[1][0] = 3;
	stuff[1][1] = 4;
	int **pointer;
	int i;
	int j;
	pointer = stuff[0][0]; //Here lies the problem: Its an incompatible pointer type
	for (i = 0; i < 2; i++){
		for (j = 0; j < 2; j++){
			printf("%i\n", (*(*(pointer+i)+j)));
		}
	}
	return 0;
}

So my problem with this is that I don't understand pointers well enough to see what is wrong with this. From what I understand, the pointer is pointing at the first memory address of array, but I get the incompatible pointer type problem, which is confusing me. Can someone explain why this is wrong and how it should be properly coded. Thanks.

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by falconwise
0

Well this is one of the duh moments. Thanks a lot, I also read up another way of doing it but your way simplifies things a lots.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.