Solved

returning array in c

Posted on 2000-02-26
2
268 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
2 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now