I have been trying to understand pointer concepts by writing simple code, and I got an error problem, and it seems like I couldn't solve it or understand it.
#include <stdio.h>
int *foo(void);
int main(void) {
printf("%d\n", *foo());
return 0;
}
int *foo(void) {
static int num = 1;
++num;
return &(++num);
}
Here is the error message.
error: lvalue required as unary ‘&’ operand
return &(++num);
Function 'foo()' returns a pointer to int, and main is supposed to be print the returned int by using * operator. For static num within foo(), I thought that by putting static qualifier, num is not temporary variable anymore, so '&' can be used to num.