First of all i would like to know why exactly case 1 gives me core dump error. secondly I want to understand if my mindset is correct.
So i created 2 cases, in the first case when i execute, i get a core dumped message and the program exits.
The other case runs and i see the result.
//case 1
//'word' is not initialized properly,or by using malloc or calloc
//as a result 'word' content will not change when you i use strcpy to copy over it
char * word = "hello";
printf("%s\n",word);
strcpy(word,"world");
printf("%s\n",word);
//case 2
//this case works because I create a static variable word with size 20
//and everytime I change it, The compiler knows where to find it in the stack.
char word[20] = "";
char * word2 = "yolo";
strcpy(word,"hello");
printf("%s\n",word); //prints hello as expected
strcpy(word,word2); //copies yolo to word
printf("%s\n",word); // prints yolo
//hence strcpy does not change the reference