By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,512 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,512 IT Pros & Developers. It's quick & easy.

returning a multi-dimensonal array

P: 2
Hi

I have just dynamiaclly created an array this way in a function

double (*price)[15]=new double[50][15]

How do I return it the main function? either by the return type of the function or by parameter passed into the function. Thanks


Tjun Kiat
May 24 '07 #1
Share this Question
Share on Google+
4 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
Hi

I have just dynamiaclly created an array this way in a function

double (*price)[15]=new double[50][15]

How do I return it the main function? either by the return type of the function or by parameter passed into the function. Thanks


Tjun Kiat
Make sure the return value matches what you are returning, and then make sure in main that there is a variable there of the same type to take it.
May 24 '07 #2

P: 2
The problem is I don't know how to define the return type for this multi dimensomal array. I tried double** but it does not work



Tjun Kiat
May 24 '07 #3

100+
P: 208
The problem is I don't know how to define the return type for this multi dimensomal array. I tried double** but it does not work



Tjun Kiat
Does double[][] not work?
May 24 '07 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
Do this:
Expand|Select|Wrap|Line Numbers
  1.    double (*price)[15]=new double[50][15];
  2.  
  3.    double (*result)[15]=new double[50][15];
  4.  
  5.    fy(price,result);
  6.  
  7.  
where:

Expand|Select|Wrap|Line Numbers
  1. void  fy( double price [][15], double result [][15] )
  2. {
  3. }
  4.  
or:

Expand|Select|Wrap|Line Numbers
  1. void  fy( double (*price)[15], double (*result)[15] )
  2. {
  3. }
  4.  
You cannot use the return type because an array is not a type. It is an array of some other type.


The example above shows fy() using arguments that that are arrays of 15 doubles. You will needadditional arguments for fy() for the number if these 15 element arrays.
May 24 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.