Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > declaring a function that returns a pointer to 1-d array

Reply
Thread Tools

declaring a function that returns a pointer to 1-d array

 
 
junky_fellow@yahoo.co.in
Guest
Posts: n/a
 
      09-17-2005
How can I declare a function that returns a pointer
to one dimensional array ?

 
Reply With Quote
 
 
 
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      09-17-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote on 17/09/05 :
> How can I declare a function that returns a pointer
> to one dimensional array ?


Do your best effort nd post it. It's basic.

(hint : malloc())

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

..sig under repair


 
Reply With Quote
 
 
 
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      09-17-2005
(supersedes <(E-Mail Removed)>)

(E-Mail Removed) wrote on 17/09/05 :
> How can I declare a function that returns a pointer
> to one dimensional array ?


Do your best effort and post it. It's basic.

(hint : malloc())


--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Mal nommer les choses c'est ajouter du malheur au
monde." -- Albert Camus.


 
Reply With Quote
 
Vimal Aravindashan
Guest
Posts: n/a
 
      09-17-2005
(E-Mail Removed) wrote:
> How can I declare a function that returns a pointer
> to one dimensional array ?
>

Like you declare any other funtion, just remember that the scope of
local variables are restricted to within the function. So you have to
return a pointer to dynamically allocated memory, or to a static variable.

cheers,
forayer

--
If you would be a real seeker after truth, it is necessary that at least
once in your life you doubt, as far as possible, all things."
-- Rene Descartes
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-17-2005
(E-Mail Removed) writes:
> How can I declare a function that returns a pointer
> to one dimensional array ?


Do you really want a pointer to an array, or do you want a pointer to
its first element (which you can then use to access all the elements)?

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
junky_fellow@yahoo.co.in
Guest
Posts: n/a
 
      09-17-2005

Keith Thompson wrote:
> (E-Mail Removed) writes:
> > How can I declare a function that returns a pointer
> > to one dimensional array ?

>
> Do you really want a pointer to an array, or do you want a pointer to
> its first element (which you can then use to access all the elements)?
>

I want a pointer to an array. (not the pointer to the first element).

 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      09-17-2005
(E-Mail Removed) wrote:
>
> Keith Thompson wrote:
> > (E-Mail Removed) writes:
> > > How can I declare a function that returns a pointer
> > > to one dimensional array ?

> >
> > Do you really want a pointer to an array,
> > or do you want a pointer to
> > its first element
> > (which you can then use to access all the elements)?
> >

> I want a pointer to an array. (not the pointer to the first element).


/* BEGIN new.c */

#include <stdio.h>

int (*f(void))[11];

int main(void)
{
printf("f()[0][2] is %d.\n", f()[0][2]);
putchar('\n');
return 0;
}

int (*f(void))[11]
{
static int a[11] = {1, 3, 5, 7};

return &a;
}

/* END new.c */


--
pete
 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      09-17-2005
pete wrote on 17/09/05 :
> int (*f(void))[11];


Scary !

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"C is a sharp tool"


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-17-2005
(E-Mail Removed) writes:
> Keith Thompson wrote:
>> (E-Mail Removed) writes:
>> > How can I declare a function that returns a pointer
>> > to one dimensional array ?

>>
>> Do you really want a pointer to an array, or do you want a pointer to
>> its first element (which you can then use to access all the elements)?
>>

> I want a pointer to an array. (not the pointer to the first element).


Ok. Why?

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
junky_fellow@yahoo.co.in
Guest
Posts: n/a
 
      09-17-2005

pete wrote:
> (E-Mail Removed) wrote:
> >
> > Keith Thompson wrote:
> > > (E-Mail Removed) writes:
> > > > How can I declare a function that returns a pointer
> > > > to one dimensional array ?
> > >
> > > Do you really want a pointer to an array,
> > > or do you want a pointer to
> > > its first element
> > > (which you can then use to access all the elements)?
> > >

> > I want a pointer to an array. (not the pointer to the first element).

>
> /* BEGIN new.c */
>
> #include <stdio.h>
>
> int (*f(void))[11];
>
> int main(void)
> {
> printf("f()[0][2] is %d.\n", f()[0][2]);
> putchar('\n');
> return 0;
> }
>
> int (*f(void))[11]
> {
> static int a[11] = {1, 3, 5, 7};
>
> return &a;
> }
>
> /* END new.c */
>
>


Thanx a lot ...

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Declaring static function returning pointer to extern function pembed2012 C Programming 1 02-27-2012 08:21 PM
Problems with function that returns a pointer to array of strings paktsardines@gmail.com C Programming 7 07-31-2007 07:15 PM
FAQ lite:10.19, Bar() part is declaring a non-member function that returns a Bar object Biermann.Pan@gmail.com C++ 2 03-15-2007 06:41 AM
Need Help Declaring a Pointer to an Array of Structures gcary@trancer.com C Programming 12 09-04-2006 04:31 AM



Advertisments