Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

returning array in c

Posted on 2000-02-26
2
Medium Priority
?
285 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 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 85

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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 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…
Suggested Courses

916 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