i have a string related doubt ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

i have a string related doubt ?

this code works fine :- int main(int argc, char **argv) { char *str; scanf("%s", str); printf("%s", str); return 0; } But not this WHY :- int main(int argc, char **argv) { char *str[5]; scanf("%s", str[0]); printf("\n%s", str[0]); return 0; } pls, help here to let me understand difference i know that second code declares an 5 string pointers. but what then?

11th Jul 2020, 2:56 PM
NIK
NIK - avatar
2 Answers
0
codemonkey i tried this on my pc and it worked thats why i have this doubt in the first place but now it is quite clear to me that i can not scan values in uninitialized situation however if i assign values like char *str ; str ="hello"; str= "world"; it works fine because str changes its value and now it is pointing to "world". i just want to clear that AM I RIGHT ?
11th Jul 2020, 4:33 PM
NIK
NIK - avatar
0
codemonkey thanks i have this cleared in my mind i want to know that just right .
11th Jul 2020, 4:47 PM
NIK
NIK - avatar