I'm trying to copy some elements from one array to another and in a way it does work but it copies the whole array when the pointer only points to one element. This is the code:
char buffer[64], buffer1[2];
char* pointer;
strcpy(buffer, "Word");
pointer = buffer1;
*pointer = buffer[0];
printf("%c\n", *pointer);
printf("%s\n", buffer1);
When I print *pointer to the console I get "W" but when I print buffer1 to the console I get "WÌÌÌÌÌÌÌÌÌWord", how is that even possible? It can only take two elements?
buffer1Wis guaranteed. It's just whatever happens to be in those memory locations. Lightness' answer provides a good explanation of what's going on.