Samsung Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
1
of 1 vote

why this code perfectly running and giving ouput 56

int main()
{
int *p=malloc(0);
*p=56;
printf("%d",*p);
return 0;
}

- kamal June 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

you can check malloc() manual in linux distros. if size in malloc() or calloc() call is zero then both of them may return NULL or some unique pointer value which may be further used by free().

- mohit89mlnc June 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

return address and if u want to print malloc(o) than
main()
{
printf("%d",malloc(0));
}
o/p is some thing address

- Anonymous April 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If size is zero, the return value depends on the particular library implementation (it may or may not be a null pointer), but the returned pointer shall not be dereferenced.

- Mauricio.Malf May 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It will point to some relevant location and according to code :

int main()
{
int *p=malloc(0);
*p=56;
printf("%d",*p);
return 0;
}

The output will be 56 only.

If we remove the statement *p=56;, the some defined memory address is printed.

- Prashant Dheer June 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int 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.

- mithleshtechno July 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Implementation dependent.
return a NULL pointer.
Same as ptr=NULL;
but realloc(ptr,new_size) works.

- Sonam April 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

int *p=malloc(0);

return some address .
checked in dev c++

- kamal June 08, 2011 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More