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 - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -