I had a job interview where I was asked two questions I couldn't solve. I would like to know what the problems with the following two snippets of code are
First question:
The question was: what's wrong in the following code?
class A
{
// Some properties ans methods
};
class B
{
// Some properties ans methods
};
void foo(A* pa, B* pb)
{
//Do somthing with pa and pb
};
void main()
{
A* pa = NULL;
B* pb = NULL;
foo(pa = new A, pb = new B);
}
Second question:
The question was: what is printed (Eventually, the interviewer told me that the answer is 17 and 0, but I don't understand why)
int counter = 0; //Global variable
int foo()
{
int i = 0;
while (i < 12)
{
// Do somthing
counter++;
i++;
}
return 17;
}
void main()
{
printf("Foo() = %d , counter = %d", foo(), counter);
}