1p3a Experience · Oct 2025

Arista Networks C++ Debugging Technical Interview Experience

SWE Technical

Interview Experience

The interview involved a debugging problem requiring the analysis of the following C++ code snippet: ```cpp #include using namespace std; void function(int *p) { int x = 100; p = &x; } int

Full Details

The interview involved a debugging problem requiring the analysis of the following C++ code snippet: cpp #include <iostream> using namespace std; void function(int *p) { int x = 100; p = &x; } int main() { int a = 10; int *ptr = &a; function(ptr); cout << "Value: " << *ptr << endl; return 0; } The output of this code is Value: 10. This occurs because the pointer p is passed to the function by value. The function creates a local copy of the pointer, so when p is reassigned to the address of x (p = &x), only the local copy is modified. The original pointer ptr in main remains unchanged and continues to point to a. To achieve the intended result of printing 100, the function must be modified to dereference the pointer and assign the value directly to the memory location, as shown below: cpp #include <iostream> using namespace std; void function(int *p) { int x = 100; *p = x; // Assigns the value of x to the memory location p points to } int main() { int a = 10; int *ptr = &a; function(ptr); cout << "Value: " << *ptr << endl; return 0; }

Free preview. Unlock all questions →