J
junky_fellow
How can I declare a function that returns a pointer
to one dimensional array ?
to one dimensional array ?
How can I declare a function that returns a pointer
to one dimensional array ?
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 ofHow can I declare a function that returns a pointer
to one dimensional array ?
How can I declare a function that returns a pointer
to one dimensional array ?
I want a pointer to an array. (not the pointer to the first element).Keith said: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).
int (*f(void))[11];
I want a pointer to an array. (not the pointer to the first element).
pete said: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 */
Keith said:Ok. Why?
The return type will be "int **" but returning 'arr' when 'arr' isKeith Thompson wrote:
[snip]Ok. Why?
There's no specific reason for this. I am learning C and this came to
my mind but I was not able to figure it out. Anyway thanx to pete
for the answer.
I also want to know how can we return a pointer to first element
of a 2-d array ? what would be the declaration for such a function
(the function that returns the pointer to the first element of
a 2d array whose elements are of type int) ?
For eg. suppose I have a 2d array
int arr[3][4];
I want to return the address of first element of arr.
Can I do
return(arr);
But then what would be the decalaration of such a function (I mean the
return type ?) will it be "int *" or "int **" ?
Thanx in advance for any help ...
I also want to know how can we return a pointer to first element
of a 2-d array ? what would be the declaration for such a function
(the function that returns the pointer to the first element of
a 2d array whose elements are of type int) ?
For eg. suppose I have a 2d array
int arr[3][4];
I want to return the address of first element of arr.
Can I do
return(arr);
But then what would be the decalaration of such a function (I mean the
return type ?) will it be "int *" or "int **" ?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.