Microsoft Interview QuestionSoftware Engineer / Developers
Interview Type: In-Person
What is i here? Not clear form the question. If i is an int. Answer is perfect. Think what if i is a int* ?
Actually Observer is perfectly saying correct.
if variable i is a pointer to float(suppose), then first line is correct and second one is incoorect.
So, it completely depends upon the nature of variable i.
In his case, 10 would definitely [ Ok most probably ] be a memory location that is allotted for the OS related basic operation..service routines etc. So, code trying to access them would fail.
In the first one an int is casted into (int*) and then it is dereferenced, hence if i was equal to 10(suppose), you are dereferencing variable at address 10, this could be a segmentation fault.- Luv June 28, 2012
The second one is fine in that p will have the value of i.