Talk About Network

Google





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

Re: Array Return

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

cplusplusquestion@[EMAIL PROTECTED]
 said:

> const int MAX=20;
> int a[MAX];

I don't know whether that's legal C++. It's legal C99, but not legal C90.
> 
> int* return_a_value(){
>      return a;
> 
> }
> 
> int main(){
>   for(int i=0; i<MAX; i++)
>      a[i] = 2;
>   int* b = return_a_value();
> 
>   for(int i=0; i<MAX; i++)
>     cout << b[i] << " ";    // DOES this right?

Because b[i] means the same as *(b + i), yes, that works just fine in C++,

provided cout is defined appropriately.

-- 
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
localhost-V2008-12-19 Wed Jan 7 13:10:58 PST 2009.