In this case, pCow
is set to the address of a c-string in static memory:
char *pCow = "pCow goes MOO";
In this case, pCow
is set to the value 'p'
(i.e., 112
):
char *pCow = {'p','C','o','w',' ','g','o','e','s',' ','M','O','O','\0'};
Since the address 112
most likely points into restricted/invalid memory, that causes your program to blow up when you try to access pCow[counter]
.
The warning "excess elements in scalar initializer" is telling you that it's ignoring all of the stuff after the 'p'
since the pointer only needs one value.
The warning "initialization makes pointer from integer without a cast" is telling you that you're using 'p'
as a pointer, which probably isn't a good idea...
What you want to do is declare pCow
as a character array rather than a character pointer if you want to use the initializer syntax:
char pCow[] = {'p','C','o','w',' ','g','o','e','s',' ','M','O','O','\0'};