I have following set of files:
file1.h:
char* path = "C:\\temp"
file2.c
#include "file1.h"
char* getFilePath(){
return path;
}
file3.c:
#include "file1.h"
int main(){
printf(" File path: %s",getFilePath);
}
When I compile the above solution, I get
LNK2005 error `char *path` already defined
However, if I change char* path to extern char* path; in file1.h:
extern char* path;
and also define it in file2.c like this:
char *path = "C:\\test"
then everything works fine. But I am not able to comprehend difference in behavior. Can somebody please explain this?