Bloomberg LP Interview Question for Interns


Country: United States
Interview Type: In-Person




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

This C++ program results in segmentation fault. It occurs in func() while trying to dereference a NULL pointer.

#include<iostream>

int *p = NULL;

int func()
{
  return *p;
}

int c = func();

int main()
{
  int a = 5;
  printf("%d",a);
  return 0;
}

- Anonymous September 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

WOAH! Cool.

- bigphatkdawg September 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

Guessing your question is for Java, static blocks are executed before main.

- Pooja Kulshrestha September 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What language and how does it crash?

In C:
- the startup code could be faulty
- gcc compiler allows you to do some funky stuff

In C++:
- define an external static duration object with some funky constructor (e.g., dereference a junk pointer inside the constructor to cause a seg fault)
- all the C stuff from above

- bigphatkdawg September 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is that the program linked to a dynamic library and it is not available in the machine where the executable is running?

- srini September 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can even get this program to crash:

int main() {
   return 0;
}

By using LD_LIBRARY_PRELOAD or equivalent.

- Anonymous September 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The gcc compiler links some stuff before giving control to main. It can be found in the crt1.c. They will pass the arguments for the program.. argc and argv. So if something goes wrong here, the program will crash before main.

- Chid December 29, 2013 | 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