Bloomberg LP Interview Question for Financial Software Developers






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

Yes. Result: 0.
Since static variable scope is defined to the file.

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

Correct

- e=mc2 March 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Anonymous: You are right. Answer is 0. Static is file-scoped.

- Bandicoot March 25, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

..and (as importantly) initialized to 0. Unlike local variables.

- bloombergoid September 06, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It will not compile. "#include" statements are missing.
'foo', 'bar' and 'printf' are undeclared identifiers.

If the header files are provided and included then the program will print '0'.

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

Or you can just declare two functions in main.cpp:
void foo();
void bar();

#include <stdio.h>
is still needed!

- Anonymous June 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not Necessary! It will compile w/o two functions declaration.

- Dev Null August 27, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

output will be 2 .

- sunil kumar kanaujia January 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Output is 2 after including both the files foo.h and bar.h.
I believe that declaring static int var in the main does not make a difference actually. It just re-iterates the fact that var is a static variable for this program and surprisingly c allows that(unlike in case of local variables, where multiple declaration is not allowed).

- Anonymous April 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Output is 2 after including both the files foo.h and bar.h.
I believe that declaring static int var in the main does not make a difference actually. It just re-iterates the fact that var is a static variable for this program and surprisingly c allows that(unlike in case of local variables, where multiple declaration is not allowed).

- Niranjan Kulkarni April 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what is the content of foo.h and bar.h

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

answer is 0 ,

the var in other files are not wrong since static var will be created in all files with its own file scope, its allowed in C.

- vijaymukilan July 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This will not compile because the functions foo() and bar() and printf() are not defined in main.c

In order for this to work an additional header is needed:

// additionalheader.h
void foo();
void bar();

The following lines must be added to the routine main():

#include <stdio.h>
#include "additionalheader.h"

The variable var will not be redefined because it is static and therefore will not be visible outside the file in which it is defined.

The result of running the resulting executable will be the value assigned to 'var' in main(). In this case that will be '0' because this is required by the C language standard.

- Wandering programmer February 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

int 'var' re-definition!!!

- Anonymous April 21, 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