0
If functions acts as pointers then why the function here needs '*' ? Please answer!!!!
#include <stdio.h> int * get_evens(); int main() { int *a; int k; a = get_evens(); /* get first 5 even numbers */ for (k = 0; k < 5; k++) printf("%d\n", a[k]); return 0; } int * get_evens () { static int nums[5]; int k; int even = 0; for (k = 0; k < 5; k++) { nums[k] = even += 2; } return (nums); }
1 ответ
+ 1
That means it returning integer pointer....
Edit:
Actually, function pointer can be assigned like normal pointers. And in your code, you are assigning function get_evens to pointer a in main as :
int (*a) = get_evens(); and using like a[k]..