Bloomberg LP Interview Question for Interns


Country: United States
Interview Type: Phone Interview




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

Pass by Value -- When a variable is passed by value. It's value is copied into the local address space that is made available to the function.Whatever changes the code in the function makes to this variable are done inside it's local space.
e.g.void swap(int a,int b){ int temp; temp=a;a=b;b=temp; }
call to this funtion swap(x,y) willl not swap the values of x and y.

Pass by reference -- When you pass by reference the compiler implicitly does this when it encounters the use of the variable in the function code. It will refer to the original variable that was passed. and the change to the value of that variable will be done at the address location it was originally placed at.
e.g. void swap(int &a,int &b){int temp; temp=a;a=b;b=temp;}
swap(x,y) ... this will interchange the values of x and y.

Pass by address ... In pass by address you do the compilers job. You explicitly catch the original address of the variable in a special variable called as a pointer. then you use the derefrencing operator to change the value in the address.
e.g. void swap(int *a, int *b){ int temp; temp = (*a); *a=*b; *b=temp; }
swap(&x,&y) .... this will interchange the values of x and y.

An array is a sequence of addresses.. Passing it by value would have been counter intuitive and would require huge amount of overhead. Hence arrays are always passed by reference.

You could define an array inside of a structure and then pass it. that would pass it by value.

- isandesh7 January 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

1) We pass by value when you don't want the value to be changed on client side which passes its value. Value is affected locally.
When we pass by reference, the value corresponding to the reference gets changed locally and globally(changed on client side too)
2) Yes, Stricture can be passed by Value and reference
3)No. Basically array value always have a reference to a object. And its is not a primitive datatype. So Array can only be passed by reference.

Note:Fixed-size arrays (size fixed at compile-time) can be part of a struct, and then they are passed by value.

I mean declarations like int foo[5]; inside a struct.
Credit: Anonymous

- googler January 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Fixed-size arrays (size fixed at compile-time) can be part of a struct, and then they are passed by value.

I mean declarations like int foo[5]; inside a struct.

- Anonymous January 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Yes, a structure can be passed by value.
2. No, an array is always passed as a reference (by address really).

- awasthi.manoj January 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a. yes
b. no

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

a. Yes. Structure can be passed by value
b. No. Array can only be passed by reference

- Swarupa August 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

Java doesn't have structures.

- Anonymous January 23, 2013 | Flag


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