← Arista Interview Insights

Arista·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Technical phone screen for a software engineer role at Arista, heavy on C fundamentals and memory model questions. Pretty low-level stuff, felt like they wanted to see if you actually understood what the compiler and OS are doing under the hood.

Questions Asked (4)

Q1

Given `const char *c = "12345"`, what does each of these printf calls actually do: `printf("%s", c)`, `printf("%d", c)`, `printf("%c", c)`, `printf("%c", *c)`, `printf("%c", *(c+1))`, and what's the correct way to print the address stored in `c`?

Technical Trade-offsRoot Cause Analysis
Author's notes

The %s and %c with dereference cases were fine, but I fumbled on %d and %c with c directly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Walk through each printf call, explaining what the format specifier expects and what is actually passed, then describe the resulting behavior (including undefined behavior). Finally, state the correct way to print the address using %p and a cast to void*.

Pro tip: Emphasize that passing a pointer to %d or %c is undefined behavior, not just a warning; this shows you understand C's type system and portability concerns.

1. Clarify the setup

Explain that c is a pointer to a string literal, so it holds the address of the first character '1'. The string is null-terminated.

2. Analyze each printf call

For each call, identify the format specifier's expected argument type and compare with the actual argument (c or *c or *(c+1)). Describe the output or undefined behavior.

3. Explain undefined behavior

Highlight that printf("%d", c) and printf("%c", c) are undefined because %d expects int and %c expects int (char promoted), but c is a pointer. The output is unpredictable and may crash.

4. State the correct way to print the address

Use printf("%p", (void*)c) to print the pointer value. The cast to void* ensures compatibility with %p.

Key Points to Mention

  • c is a pointer to char, initialized to the address of the string literal "12345".
  • %s expects a char* pointing to a null-terminated string, so printf("%s", c) prints the string.
  • %d expects an int, but c is a pointer; passing a pointer to %d is undefined behavior.
  • %c expects an int (character), but c is a pointer; passing a pointer to %c is undefined behavior.
  • *c dereferences c to get the first character '1', so printf("%c", *c) prints '1'.
  • *(c+1) dereferences the next character '2', so printf("%c", *(c+1)) prints '2'.
  • To print the address, use %p with a cast to void*: printf("%p", (void*)c).

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

Q2

How would you use gdb or lldb to inspect the pointer value of `c`, the raw bytes at that address, and the string stored there?

Technical Trade-offs
Author's notes

I use gdb occasionally but not constantly, so I blanked on the exact lldb syntax.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Walk through a concrete debugging session: first print the pointer value, then examine the raw memory bytes at that address, and finally interpret those bytes as a C string. Emphasize the exact commands and format specifiers used in gdb/lldb, and explain how each step builds on the previous one.

Pro tip: Mention that you can combine steps using gdb's `x/s` or lldb's `memory read -c` to directly view the string, but always verify the pointer is non-null and points to valid memory first to avoid crashes or misleading output.

1. Print the pointer value

Use `p c` (gdb) or `frame variable c` / `p c` (lldb) to display the address stored in the pointer. Note the format (e.g., 0x7ffff7f...).

2. Examine raw bytes at that address

In gdb, use `x/16xb c` to show 16 bytes in hex; in lldb, use `memory read --format x --size 1 --count 16 c`. This reveals the actual byte sequence.

3. Interpret bytes as a string

In gdb, use `x/s c` to print the null-terminated string; in lldb, use `memory read --format c --size 1 --count <n> c` or `p (char*)c` to see the string representation.

4. Verify and contextualize

Check that the pointer is not null and that the memory is readable (e.g., `x/1gx c` to see the first 8 bytes). Explain how the raw bytes map to characters (e.g., ASCII/UTF-8).

Key Points to Mention

  • gdb commands: `p`, `x/xb`, `x/s`, and format specifiers like `xb`, `s`.
  • lldb equivalents: `p`, `memory read`, `frame variable`, and options like `--format`, `--size`, `--count`.
  • Pointer dereferencing: `c` is the address, `*c` is the first byte, `(char*)c` treats it as a string.
  • Endianness and byte order when inspecting multi-byte values (though for char strings it's straightforward).
  • Safety checks: ensure pointer is non-null and points to valid memory before dereferencing.
  • Difference between viewing raw bytes and interpreting them as a null-terminated string.

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

Q3

Compare malloc/free versus new/delete in C and C++, covering initialization behavior, constructor and destructor calls, type safety, failure handling, and array variants.

Technical Trade-offsSystem Design
Author's notes

Solid ground for me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying that malloc/free are C library functions for raw memory allocation, while new/delete are C++ operators that combine allocation with object construction/destruction. Then systematically compare them across the requested dimensions: initialization, constructor/destructor calls, type safety, failure handling, and array variants, highlighting practical implications for C++ development.

Pro tip: Emphasize that mixing malloc/free with new/delete leads to undefined behavior, and mention that modern C++ often prefers smart pointers and containers over raw new/delete, showing awareness of best practices.

1. Define and Contrast Basics

Explain that malloc/free are functions that allocate/deallocate raw memory, while new/delete are operators that allocate memory and call constructors/destructors. Mention they are not interchangeable.

2. Initialization and Object Lifecycle

Discuss that malloc returns uninitialized memory, whereas new initializes objects by calling constructors. Similarly, free does not call destructors, but delete does.

3. Type Safety and Failure Handling

Highlight that new returns a properly typed pointer, while malloc returns void* requiring a cast. For failure, malloc returns NULL, while new throws std::bad_alloc by default (or returns NULL if nothrow is used).

4. Array Variants and Customization

Cover new[] and delete[] for arrays, which call constructors/destructors for each element. Mention that malloc/free have no array-specific variants and that new/delete can be overloaded for custom memory management.

5. Summarize Trade-offs and Best Practices

Conclude that in C++, new/delete are preferred for object management due to safety and lifecycle support, but malloc/free may be used for raw memory or C interoperability. Warn against mixing them.

Key Points to Mention

  • malloc/free are C functions; new/delete are C++ operators.
  • new calls constructors and delete calls destructors; malloc/free do not.
  • new is type-safe and returns a typed pointer; malloc returns void*.
  • malloc returns NULL on failure; new throws std::bad_alloc (or returns NULL with nothrow).
  • new[] and delete[] handle arrays and call constructors/destructors for each element.
  • Mixing malloc/free with new/delete is undefined behavior; use matching pairs.

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

Q4

What typically lives in the stack, heap, data segment, BSS segment, and text segment? Where does a string literal like "12345" end up?

System DesignTechnical Trade-offs
Author's notes

String literals in the text or read-only data segment, not the stack, was the key point and I got that right.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining each memory segment and its purpose, then map typical contents to each segment. Finally, address the string literal example by explaining its storage location and mutability, and discuss common misconceptions.

Pro tip: Mention that string literals are stored in a read-only area of the data segment (often called .rodata), and that identical literals may be pooled—this shows depth and awareness of compiler optimizations.

1. Define the segments

Briefly explain the purpose of each segment: stack for automatic variables and function call context, heap for dynamic allocation, data for initialized global/static variables, BSS for uninitialized global/static variables, and text for executable code.

2. Map typical contents

List what typically resides in each: stack (local variables, parameters, return addresses), heap (malloc/new allocations), data (initialized globals/statics), BSS (zero-initialized globals/statics), text (machine instructions, string literals).

3. Address the string literal

Explain that a string literal like "12345" is stored in the read-only data segment (often .rodata), not on the stack or heap, and that it has static storage duration.

4. Discuss mutability and pooling

Note that modifying a string literal is undefined behavior; also mention that compilers may pool identical string literals to save space.

5. Summarize with a clear example

Provide a concise example (e.g., char *s = "12345";) to illustrate where the pointer and the string data reside, reinforcing the distinction.

Key Points to Mention

  • Stack: local variables, function arguments, return addresses; grows downward.
  • Heap: dynamically allocated memory (malloc, new); managed manually or via garbage collection.
  • Data segment: initialized global and static variables; further divided into read-only (.rodata) and read-write (.data).
  • BSS segment: uninitialized global and static variables; zero-initialized at program start.
  • Text segment: executable code; often read-only and shared.
  • String literals: stored in .rodata (read-only data segment); immutable; may be pooled.

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