I was experimenting with pointers and I noticed this...
Code:
#include <stdio.h>
int variable = 10;
int *pointer;
pointer = &variable;
void address (int test)
{
printf("%d\n", test);
}
void fpointer (int *test)
{
printf("%d\n", *test);
printf("%d\n", test);
}
void main ()
{
address(*pointer);
fpointer(&variable);
}
When I tried to compile with gcc, and I get these errors:
Code:
point.c:5: warning: data definition has no type or storage class
point.c:5: error: conflicting types for ‘pointer’
point.c:4: note: previous declaration of ‘pointer’ was here
point.c:5: warning: initialization makes integer from pointer without a cast
If I move lines 4-6 inside main, the program compiles...
Why can't I initialize a pointer outside main?
Bookmarks