c - How to change the value of char pointer? -


this main:

int main(void) {     char w1[] = "paris";     changetheword(w1);     printf("the new word is: %s",w1);     return0; } 

and need change value of w1[] in function:

changetheword(char *str) {       ...  } 

int main() {     char w1[]="paris";     changeword(w1);      // means address of w1[0] i.e &w[0]     printf("the new word %s",w1);     return 0;  } void changeword(char *str)  {     str[0]='d';         //here str have same address w1 whatever did str refected in main().      str[1]='e';     str[2]='l';     str[3]='h';     str[4]='i'; } 

read this answer too


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -