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?
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 ?
0
codemonkey thanks i have this cleared in my mind i want to know that just right .