I fell over this little thing while coding:
char* strinit(char* str) {
str = (char*) malloc(100);
strcpy(str, "hello SO");
return str;
}
int main()
{
char* str = strinit(str);
return 0;
}
As you can see, I am using the same variable that I am declaring to initialize it. This is no problem. I tried the same thing in Java. That causes errors.
So my question is: Is there any problems doing this? Can I use it in my code in good conscience?