I'm new to C especially new to C pointers. The problem here is simple:
#include <stdio.h>
char *p1 = "Hello";
char *p2;
p2 = "world"; // error: redefinition of 'p2' with a different type: 'int' vs 'char *'
int main()
{
char *p3 = "Hello";
char *p4;
p4 = "world"; // OK! p4 can re-point to somewhere
return 0;
}
I declare a global pointer p2, but I try to assign a string, "hello",to it.
But QT prompt a error: redefinition of 'p2' with a different type: 'int' vs 'char *'
It says p2 is a int? But I clearly declared it a char *;
However, p4, as a local pointer, can do the same thing! All works fine in main function.
What's going on? I'm confusing!