Samsung Interview Question
Software Engineer / Developersint main()
{
int *p=malloc(0);
*p=56;
printf("%d",*p);
return 0;
}
malloc return the void pointer and we know void pointer can be assigned in any kind of pointer without typecasting .
so here pointer p store the address of void pointer which returned by malloc, and at that address you are performing write operation by storing value 56,that's why it print 56.
why this code perfectly running and giving ouput 56
- kamal June 08, 2011int main()
{
int *p=malloc(0);
*p=56;
printf("%d",*p);
return 0;
}