Bloomberg LP Interview Question
Financial Software DevelopersIt 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'.
Or you can just declare two functions in main.cpp:
void foo();
void bar();
#include <stdio.h>
is still needed!
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).
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).
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.
Yes. Result: 0.
- Anonymous March 23, 2010Since static variable scope is defined to the file.