PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Software Engineering Fundamentals/Arista

Explain C printf pointers and memory layout

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of C pointer semantics, printf format-specifier behavior, memory layout and allocation differences, and practical debugger usage for inspecting addresses and bytes, within the Software Engineering Fundamentals domain.

  • easy
  • Arista
  • Software Engineering Fundamentals
  • Software Engineer

Explain C printf pointers and memory layout

Company: Arista

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Technical Screen

You are given the following C code: ```c const char *c = "12345"; ``` Answer the following (assume typical modern 64-bit Linux/macOS with GCC/Clang, unless a behavior is undefined/implementation-defined): 1. What does each of the following intend to print, and what actually happens? - `printf("%s", c);` - `printf("%d", c);` - `printf("%c", c);` - `printf("%c", *c);` - `printf("%c", *(c+1));` - What is the correct way to print the address stored in `c`? 2. Explain how you would use `gdb`/`lldb` to inspect: - the value of `c` (as an address) - the bytes at that address - the string starting at that address 3. Memory and allocation fundamentals: - Compare `malloc/free` vs `new/delete` in C/C++ (initialization, constructors/destructors, type safety, failure behavior, arrays, etc.). - Describe what typically lives in the **stack**, **heap**, **data/BSS**, and **text (code)** segments. Where does a string literal like `"12345"` typically reside?

Quick Answer: This question evaluates understanding of C pointer semantics, printf format-specifier behavior, memory layout and allocation differences, and practical debugger usage for inspecting addresses and bytes, within the Software Engineering Fundamentals domain.

Related Interview Questions

  • Explain Out-of-Bounds Bugs and Infinite Loops - Arista (easy)
Arista logo
Arista
Oct 4, 2025, 12:00 AM
Software Engineer
Technical Screen
Software Engineering Fundamentals
13
0

You are given the following C code:

const char *c = "12345";

Answer the following (assume typical modern 64-bit Linux/macOS with GCC/Clang, unless a behavior is undefined/implementation-defined):

  1. What does each of the following intend to print, and what actually happens?
    • printf("%s", c);
    • printf("%d", c);
    • printf("%c", c);
    • printf("%c", *c);
    • printf("%c", *(c+1));
    • What is the correct way to print the address stored in c ?
  2. Explain how you would use gdb / lldb to inspect:
    • the value of c (as an address)
    • the bytes at that address
    • the string starting at that address
  3. Memory and allocation fundamentals:
    • Compare malloc/free vs new/delete in C/C++ (initialization, constructors/destructors, type safety, failure behavior, arrays, etc.).
    • Describe what typically lives in the stack , heap , data/BSS , and text (code) segments. Where does a string literal like "12345" typically reside?

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Software Engineering Fundamentals•More Arista•More Software Engineer•Arista Software Engineer•Arista Software Engineering Fundamentals•Software Engineer Software Engineering Fundamentals
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.