Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parallel arrays 1

Status
Not open for further replies.

lanre1

Programmer
Jan 18, 2004
1
US
Hello,
i'm so new to the C malloc() so i need some programer supervission on it. In the dynamic allocation of memory using malloc() to return the value of a proper type is it proper to do something like the following:

int **space;
// allocates memory space
for(i=0, i<n; i++)
space = (int*)malloc(n * sizeof(int*));

-----------------------------
| | | | | | | |
| | | | | | | |
-----------------------------
does this next code also creat a parall array
or do i have to reallocate another memory space as i did befor?

space=(int*)malloc(sizeof data);

if I have misunderstood parrall array please redirect me.

Thank to all
 
I'm not sure what you're trying to achieve here, your use of malloc is wrong.

To allocate some memory which has the same subscripts as int arr[X][Y], you would do this
Code:
int **arr;
arr = malloc( X * sizeof *arr );
for ( i = 0 ; i < X ; i++ ) arr[i] = malloc( Y * sizeof *arr[i] );

--
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top