Solved

returning array in c

Posted on 2000-02-26
2
267 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

758 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

12 Experts available now in Live!

Get 1:1 Help Now