memcpy Function in C
Level 4267 keystrokes
Uses memcpy to copy an entire struct from source to destination memory.
C code
// Define simple Point structure1struct Point {2 int x, y;3};4 // Source struct with values5struct Point src = {100, 200};// Destination struct (uninitialized)6struct Point dest;// memcpy(destination, source, byte count) copies the raw bytes7memcpy(&dest, &src, sizeof(struct Point));// Print source values8printf("Source: (%d, %d)\n", src.x, src.y);// Print copied values in destination9printf("Dest: (%d, %d)\n", dest.x, dest.y);// Two 4-byte ints: 8 bytes on common systems10printf("Size copied: %lu bytes\n", sizeof(struct Point));Output
Source: (100, 200) Dest: (100, 200) Size copied: 8 bytes
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
,× 11;× 8(× 8)× 8"× 6%× 5.× 4:× 3\× 3{× 2