Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Re: Array Retur...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 7 Topic 4112 of 4294
Post > Topic >>

Re: Array Return

by Richard Heathfield <rjh@[EMAIL PROTECTED] > Apr 14, 2008 at 09:21 AM

cplusplusquestion@[EMAIL PROTECTED]
 said:

> 
>> It isn't clear what you mean by "will return a[MAX] value" but, since
>> there is no value available at array element a[MAX], it seems you may
>> want to return the entire array. The above code will not achieve this.
>> Instead, it will return &a[0]. That is probably adequate for your
needs,
>> however.
>>
> 
> for example:
> 
> const int MAX=20;
> int a[MAX];
> 
> int* return_a_value(){
>      return a;
> }
> 
> int main(){
>   for(int i=0; i<MAX; i++)
>      a[i] = 2;
>   int* b = return_a_value();

b now points to a[0]. Obviously *b will be 2, which doesn't help us much. 
But if we change the code to this:

  for(int i=0; i<MAX; i++)
     a[i] = i;
  int* b = return_a_value();

we can now say that *b will be 0.

-- 
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www.
+rjh@[EMAIL PROTECTED]
 users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 




 7 Posts in Topic:
Array Return
cplusplusquestion@[EMAIL   2008-04-14 01:41:28 
Re: Array Return
Richard Heathfield <rj  2008-04-14 09:08:49 
Re: Array Return
cplusplusquestion@[EMAIL   2008-04-14 02:14:18 
Re: Array Return
Richard Heathfield <rj  2008-04-14 09:21:47 
Re: Array Return
cplusplusquestion@[EMAIL   2008-04-14 02:22:29 
Re: Array Return
Richard Heathfield <rj  2008-04-14 11:01:29 
Re: Array Return
"Daniel T." <  2008-04-14 06:58:11 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 15:33:37 CDT 2008.