954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to convert array subscript to pointer subscript

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]);
}
mike.bauer
Newbie Poster
6 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

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

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

what if I want to increment the row:

eq->pt_tree[0][1]=6;
mike.bauer
Newbie Poster
6 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

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

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You