c - using variable in initialization of same variable -
i fell on 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 can see, using same variable declaring initialize it. no problem. tried same thing in java. causes errors.
so question is: there problems doing this? can use in code in conscience?
c & c++ consider char* str = strinit(str);
legal; because evaluated to:
char* str; str = strinit(str);
Comments
Post a Comment