Area of Improvements
Review your assessments and practice โ drill into each subject, then each attempt, then each question.
Back to summary
C Programming ยท Round 1
Question 9 of 10
Topic: Keywords & identifiersDifficulty: MediumBloom: Analyze
Question
Optimise a naive string-copy implementation step by step.
Result
Knowledge
68%
Delivery
74%
Technical relevancy
70%
Technical term match
62%
Your recording
Your transcript
The naive version is a while loop copying char by char until the null terminator. To optimise you could copy a word at a time, like 4 or 8 bytes. You have to be careful about alignment and the trailing bytes.
Better answer
Start from while (*d++ = *s++); โ correct but byte-at-a-time. Step 1: align both pointers to a word boundary. Step 2: copy word-at-a-time using a has-zero-byte bit trick to detect the terminator. Step 3: handle the tail bytes. Step 4: on modern CPUs, prefer the libc implementation (often SIMD). Always benchmark โ naive code is fine for short strings.
Coverage
Hit 3 of 5- Starts from the canonical naive implementation
- Moves to word-at-a-time copy
- Addresses alignment of source and destination
- Mentions has-zero-byte bit trick
- Notes libc/SIMD likely beats hand-rolled code
Gaps
- Did not mention has-zero-byte detection trick
- Skipped 'measure before optimising' guidance
Misconceptions
None detected.

