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); 

see why 'int = i;' legal?


Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -