-1

Output is:Hello Hello As you can see the image Can someone tell why I am getting this output! Destination is Capable of holding only one character then how it can print entire string.

1 Answers1

0

Please include the core part of your code otherwise we can't help you.

However, keep in mind that in C there is no automatic memory allocation, garbage collector and string type (which is an array of characters instead).

strcpy copies the entire source string to the pointer specified as the destination and stops only when it finds the NULL or \0 character regardless of how large the destination buffer is.

What happens is definitely a buffer overflow, the data following the destination buffer (of one byte) is overwritten, potentially causing program instability and data corruption.

Marco Sacchi
  • 712
  • 6
  • 21