954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

returning an array?

Does c++ allow returning an array from a function?

Thanks all,
Nate

Coach_Nate
Light Poster
48 posts since Aug 2004
Reputation Points: 14
Solved Threads: 1
 

No.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

yes.

char * foo()
{
   static char array[] = "Hello World";
   return array;
}

int* foo1()
{
   static int array[20];
   return array;
}
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

no as an array.

yes as a pointer or object such as std::vector

Stoned_coder
Junior Poster
164 posts since Jul 2005
Reputation Points: 19
Solved Threads: 5
 

yes.

char * foo()
{
   static char array[] = "Hello World";
   return array;
}

int* foo1()
{
   static int array[20];
   return array;
}

You should see this link POST

SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You