c memcpy

#include <stdio.h>
#include <string.h>

int main() {
    char source[] = "Hello, memcpy!";
    char destination[20];

    memcpy(destination, source, strlen(source) + 1);

    printf("Source: %s\n", source);
    printf("Destination: %s\n", destination);

    return 0;
}
  1. Include Libraries: Include necessary libraries (stdio.h and string.h).

  2. Main Function: Define the main() function.

  3. Variable Declaration: Declare two character arrays source and destination. source contains the string "Hello, memcpy!" and destination is an empty array of size 20.

  4. Memcpy Function: Use memcpy() to copy the content of source to destination. The parameters are:

  5. destination: The memory location where the content will be copied.
  6. source: The memory location of the content to be copied.
  7. strlen(source) + 1: The number of bytes to copy, calculated using strlen(source) (length of the string) plus 1 (to include the null terminator).

  8. Print Statements: Print the content of source and destination using printf().

  9. Return: End the main() function with a return statement, indicating successful execution.