← PayPal Interview Insights

PayPal·Software Engineer·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

PayPal technical phone screen for a software engineer role, pretty deep on C++ internals. One question, but they really wanted you to know the details, not just the surface answer.

Questions Asked (1)

Q1

In C++, if you write `std::string a = "123"; std::string b = a;`, what operations are invoked under the hood? Walk through copy construction vs move semantics, how memory allocation typically works, Small String Optimization, and why the standard doesn't mandate copy-on-write.

Technical Trade-offsSystem Design
Author's notes

I knew the basics but stumbled a bit on SSO.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining that `std::string b = a;` invokes the copy constructor, which typically allocates new memory and copies the character data. Then contrast this with move construction, which transfers ownership without allocation. Finally, discuss Small String Optimization (SSO) and why copy-on-write is not mandated by the standard, emphasizing performance and thread-safety trade-offs.

Pro tip: Mention that SSO avoids heap allocation for short strings, which is why `std::string a = "123";` likely stores the characters inline. Also, note that C++11 banned copy-on-write implementations in practice due to thread-safety and iterator invalidation issues, even though the standard doesn't explicitly forbid it.

1. Identify the operation

Explain that `std::string b = a;` is copy initialization, which calls the copy constructor of `std::string`.

2. Describe copy construction

Detail that the copy constructor allocates a new buffer (unless SSO applies) and copies the character data from `a` to `b`.

3. Contrast with move semantics

Explain that if `a` were an rvalue (e.g., `std::string b = std::move(a);`), the move constructor would be invoked, transferring ownership of the buffer without allocation.

4. Discuss memory allocation and SSO

Describe how dynamic allocation works for long strings, and how SSO stores short strings inline within the string object to avoid heap allocation.

5. Address copy-on-write

Explain that the standard does not mandate COW because it complicates thread safety and iterator invalidation; most implementations avoid it for performance and simplicity.

Key Points to Mention

  • Copy constructor vs. move constructor invocation
  • Heap allocation and deallocation for dynamic strings
  • Small String Optimization (SSO) and its typical buffer size (e.g., 15-22 characters)
  • Move semantics: transferring ownership without copying
  • Why copy-on-write is not used: thread-safety, iterator invalidation, and complexity
  • The standard's flexibility: it doesn't mandate COW, allowing implementations to choose

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.