I want to store a string "hello"
in an array of characters char arr[10]
when I run the following code:
#include <stdio.h>
int main(void)
{
char arr[10] = "Hello";
printf("%s", arr);
}
The output is generated fine. But when this code below is run, I get an error
#include <stdio.h>
int main (void)
{
char arr[10];
char * str = "Hello";
arr = str;
printf("%s", arr);
}
Why is that in the first case the string can be stored in the array and not in the second case?
Is there a way I can store "hello"
in the second case?