Quick question about C programming. I haven't taken a course on it, but was reading online about pointers and the various notations used. Does the following line result in an array of 10 pointers to integers, or a pointer to an array of 10 ints?
int *x[10];
Also does the following result in a function that takes a double as input and returns a pointer to a character?
char (*f) (double a);
Thanks in advance!
Edit: Typed the first line of code incorrectly.
A function that takes a double as input and returns a char pointer would look like this:
char * foo(double arg);
Where arg is your input double, foo is the name of the function, and char * is the return type, a char pointer.
char (*foo)(double arg);
Declares a function pointer to a function that takes a double (arg) and returns a char.
Your attempt at creating an array is missing a variable name. And there are two different ways to do this...
int * array[10];
This declares an array with 10 indexes that holds int *, int pointers.
int (*array)[10];
This declares a pointer to an array of ints with size of 10.
int *x[10]; means that x is an array with 10 elements, each of which is a pointer to int.
char (*f) (double a); means that f is a pointer to a function that returns char and has one parameter of type double.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With