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
Post a Comment