Arista Networks Interview Question for Software Engineers

Country: India
Interview Type: Written Test

Comment hidden because of low score. Click to expand.
of 1 vote

Interesting question.

Normally you declare a static array like this:
const int m = 10, n = 12;

int ar[m][n];

But that would not take malloc-ed memory. To take malloc-ed memory you have to have a pointer type. It can be done like this:

const int m=10, n=12;
int (*ar)[m][n] = (int(*)[m][n]) malloc(sizeof(*ar));
//Access elements:
(*ar)[1][2] = 3;
// Free the memory.
free(ar); ar = nullptr;

It would be extremely rare that some one would use such a code construct. But the language allows it.

- Anthony Mai January 17, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

int ** A = (int**) malloc(m * sizeof(int *));
for(int i =0; i<m; i++)
	A[i] = malloc(n * sizeof(int));

//You can access each element as A[i][j] now//

- sraman.iisc April 12, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

a = malloc(mn*sizeof(int));

- Anonymous February 18, 2017 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More