Arista Networks Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

I'm getting a segmentation fault when i try to run the second part. I'm using gcc version 4.5.3 (GCC). I think it is due to "format ‘%s’ expects type ‘char *’, but argument has type ‘void *’ " refer to bugs.centos.org/view.php?id=4128

- anirudh March 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

I'd rather copy paste the info here:
From gdb backtrace, seems that printf("%s\n", x) is being silently converted into puts(x) which is fine except when x is NULL, where printf shows (null) but puts() segfaults.
Changing the string, or using the return value avoids this "optimization".
Changing the optimization level -O doesn't affect it.

- Optimus September 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

It is caused by GCC optimization.

(gdb) disassemble main
Dump of assembler code for function main:
   0x0000000000400544 <+0>:	push   %rbp
   0x0000000000400545 <+1>:	mov    %rsp,%rbp
   0x0000000000400548 <+4>:	mov    $0x40065c,%eax
   0x000000000040054d <+9>:	mov    $0x0,%esi
   0x0000000000400552 <+14>:	mov    %rax,%rdi
   0x0000000000400555 <+17>:	mov    $0x0,%eax
   0x000000000040055a <+22>:	callq  0x400440 <printf@plt>
   0x000000000040055f <+27>:	mov    $0x0,%edi
   0x0000000000400564 <+32>:	callq  0x400430 <puts@plt>
   0x0000000000400569 <+37>:	mov    $0x0,%eax
   0x000000000040056e <+42>:	pop    %rbp
   0x000000000040056f <+43>:	retq   
End of assembler dump.
(gdb)

- JW December 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

That's really weird.

- eugene.yarovoi January 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In vs2008 both works,
second set gives
(null)
(null)

- abhishekatuw January 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Works perfectly fine on linux too.

machine:~/cfiles > ./a.out
test (null)
test (null)
machine:~/cfiles > vi NULL.c
machine:~/cfiles > gcc NULL.c
machine:~/cfiles > ./a.out
test (null)
test (null)
(null)
(null)
machine:~/cfiles > vi NULL.c
machine:~/cfiles > gcc NULL.c
machine:~/cfiles > ./a.out
(null)
(null)
machine:~/cfiles >

- Abhishek February 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Works perfectly fine on linux too.

machine:~/cfiles > ./a.out
test (null)
test (null)
machine:~/cfiles > vi NULL.c
machine:~/cfiles > gcc NULL.c
machine:~/cfiles > ./a.out
test (null)
test (null)
(null)
(null)
machine:~/cfiles > vi NULL.c
machine:~/cfiles > gcc NULL.c
machine:~/cfiles > ./a.out
(null)
(null)
machine:~/cfiles >

- Abhishek February 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Probably Due to Kernel Buffering Issues , since buffered I/O is done , some mechanism must be there to flush the buffer out implicitly

- Vijeenrosh P.W August 29, 2012 | Flag Reply


Add a Comment
Name:

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

Books

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

Videos

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