Home > Software design >  How many bytes are copied when I use the strcpy function on a String of n characters?
How many bytes are copied when I use the strcpy function on a String of n characters?

Time:08-20

for example,

char pass[0x10];
char str1[0x10] = "hello";
strcpy(string1, str1)

Does this copy 1 * 5 bytes, plus 1 more bytes of the \0 null terminator? So 6?

Im pretty new to low level, so I'm struggling to understand the Bytes concept.

CodePudding user response:

strcpy:

Copies the null-terminated byte string pointed to by src, including the null terminator, to the character array whose first element is pointed to by dest.

CodePudding user response:

"hello" is a string of 6 characters as in C, a string includes the null character.

"string is a contiguous sequence of characters terminated by and including the first null character." C17 § 7.1.1.1

All 6 are copied with strcpy().

  • Related