#include <stdio.h>
int* func()
{
static int a = 5; /* line 5 */
printf("%d\n",++a);
return &a; /* line 7 */
}
int main(void)
{
int *b = func(); /* line 12 */
(*b)++;
func();
}
This is a code example of test for coding job so it is not necessary optimal. I have basic knowledge of c++ and Java but these are pointers in C which I have trouble with.
func()'s return type is pointer but it returns the adress of the integer (line7). Does the fact that integer is static(line 5) have to do anything with this?
What does line 12 actually do?
Output of this code is:
6
8