Bloomberg LP Interview Question for Software Engineer / Developers






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

1. The number of iterations depends on sizeof(int) which is platform dependent.
2. The first value will be 255 since the pointer doesn't change if i==0.
3. Then the behavior is undefined.

- sergei June 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

nice!

- xx June 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

255
255
255
255

- Deepak May 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a bit of correction in the question..
actually the question is:
cout<<*(int *)(p + i)<<"\n"; instead of cout<<*(int *)p<<"\n";

- Anonymous May 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Taking into account this correction, output will be either
0
0
0
255

or

255
0
0
0

depending on endianness of the architecture

- gevorgk May 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

if it is (p+i) like the op said...it would give a seg-fault/bus error..otherwise 255 4 times..

- Anonymous May 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

No error reported. It seems that the results are random.

- kingming May 15, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can anyone explain why does it give random results ?

- nik May 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Depending on endianness, when we do typecast to char *, i would fetch either Hex x00 or xFF. When we again convert from char* to Int*, the 00 or FF would go to lower byte but upper byte might have anything which is in memory so logically it should be random output.

- Man May 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

SEG_FAULT may occur if the address goes beyond the permitted address range. Other wise some garbage will be printed.

- pkorhale@asu.edu March 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

what are you guys doing?
simply convert int to char, and back to int.
Then 4 255's.

- beyondfalcon May 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The data width of the machine will be logically equal to larger than ints. So it is a 32 bit machine, ints should be in 32 bits which is 4 bytes. I think the addressing scheme will be limited only to 32 bits or 4 bytes. so p will point to 4 bytes, p+1 will point to a next memory location which is again 4 bytes (but some random value)

- landyaBhai May 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I ran it on my x86 machine. It gave below output -
255
0
0
0

Mine is a little-endian machine. Now, you can guess the answer.

- Gopal June 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

In my machine it printed.

255
255
255
255

now you guess the answer

- hajju October 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 vote

15
15
15
15

- Uk May 15, 2010 | 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