Yesterday in my interview I was asked this question. (At that time I was highly pressurized by so many abrupt questions).
int *p;
*p=23;
printf("%d",*p);
Is there any problem with this code?
I explained him that you are trying to assign value to a pointer to whom memory is not allocated.
But the way he reacted, it was like I am wrong. Although I got the job but after that he said Mohit think about this question again. I don't know what he was trying to say. Please let me know is there any problem in my answer?
EDIT I added the code on the sheet;-
int *p;
p=malloc(sizeof(int));
*p=23;
printf("%d",*p);
This must be the perfect code...Am i right..
EDIT2
int *p;
*p=23;
OR
int *p=23;
I think both has problem. Cause some body is saying about the title of the post.