Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

returning array in c

Posted on 2000-02-26
2
Medium Priority
?
284 Views
Last Modified: 2010-04-21
How can you set a function that returns an array type?
I tried for example : int[ ] check( int [ ] ) { .... }
but it doesn't work..
Can I get around it with using typedef?
Is there a way of getting around it without using typedef?

 thank you,
0
Comment
Question by:anemos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 200 total points
ID: 2561185
How about:


int *check(int a)
{
  static int b[10];
  b[0] = a;
  return(b)
}

main()
{
  int *a;
  a = check(2);
  printf("%d\n", a[0]);
}

Or am I misunderstanding your question.
0
 
LVL 84

Expert Comment

by:ozo
ID: 2561661
You can return a pointer to an array (or to the first element of the array)
You can also return a structure containg an array.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question