Bloomberg LP Interview Question
It`s not C++ code: dynamically allocated arrays cannot been initialized. And in commens wrong slashes. More simple code to show problem:
int *p = new int(11);
int& ref = *p;
cout << ref; // output 11
delete p; // <--- here p is being deleted and reference ref is no more alive
cout << ref; // output garbage
Well, the comments are wrong. but it is C++ code. you can initialize an array as "myArray = new int[2]{ 100, 200 };"
it is called initialization list. compile your code with -std=c++0x switch in Makefile.
- SamOnYoun November 24, 2010