republican-creole
site Search:


 
    All Forums Hot Topics Gallery






how-to block ads


 
Search Topic:
Uniqs:
312
Share Topic
Posting?
Post a:
Post a:
Links: ·How To Get Noticed ·Web Monks FAQ ·Webhosting FAQ ·Posting Code ·How To Post ·Webhosting forum
AuthorAll Replies


dipak1296

@14.139.69.x

array of pointer to a 2-d array

hi i want to create a array of pointer to a 2-d array of int type??
specs are that each 2-d array can have different dimensions given by user dynamically...and how to access it..

By Now what i have done is
int (*arr)[dim] = x //x is a 2d array
but how to create array of pointer for it and with each array holding different dimention???

any help would be appreciable.......thank you

dave
Premium,MVM
join:2000-05-04
not in ohio
kudos:7
Reviews:
·Verizon FiOS
·Verizon Online DSL

If you're talking about C, you can't. The dimensions of an array are part of its type. An array is a sequence of elements of the same type. Therefore you can't have an array of pointers to dfferent types.

You'd have to have an array of pointers-to-int, and then deal with the fact that each pointer-to-int is a really a pointer to an arrray of array of int, of some dimensions that have to be managed outside the type system.

Or you could write in C++, where you can define any type you want, as long as you're prepared to program it.

class Matrix { Matrix(int n, int m); ... };
std::vector<Matrix*> whatever;
 


cdru
Go Colts
Premium,MVM
join:2003-05-14
Fort Wayne, IN
kudos:5

reply to dipak1296
What you are looking to do is called a jagged array. Google "jagged array language" where [language] is your particular language you're implementing it in.


Friday, 01-Jun 22:53:36 Terms of Use & Privacy | feedback | contact | Hosting by nac.net - DSL,Hosting & Co-lo
over 12.5 years online © 1999-2012 dslreports.com.
Most commented news this week
Hot Topics