How do I rewrite eq->pt_tree[0][0]=2; to user pointer subscript?

#include <stdio.h>
#include <stdlib.h>  
///////////////////////////////
struct eq_values{
	int * pt_tree[2];
}; 
////////////////////////////////
void main (){
	struct eq_values input, *eq;
	int i =2;
	eq = &input;

	while(i--){
		eq->pt_tree[i] = (int *) malloc(3 * sizeof (int));
		if (!eq->pt_tree[i]){ printf("No\n"); exit(0); }
	}
	eq->pt_tree[0][0]=2;
	printf("%i",eq->pt_tree[0][0]);
}

Recommended Answers

eq->pt_tree[row][col] = value; is equivalent to *(eq->pt_tree[row] + col) = value; .

Jump to Post

All 3 Replies

(*eq->pt_tree[0]) = 2; .

what if I want to increment the row:

eq->pt_tree[0][1]=6;

eq->pt_tree[row][col] = value; is equivalent to *(eq->pt_tree[row] + col) = value; .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.