Yahoo Interview Question for Software Engineer / Developers






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

#define sizeof_type( type ) (size_t)((type*)1000 + 1 )-(size_t)((type*)1000)

- Anonymous September 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

More precise way...

#define sizeof_macro(type_t) ((unsigned)((type_t *)0 + 1))

But this code is non-portable (Ref. C Ref Manual, by Steele and Harbision). We need to test this peace of code prerior to using in the application. offsetof also a non-portable macro.

- Venki September 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

*piece* of code...

- Anonymous September 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

*prior* to using...

- Mahesh September 15, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

*piece* of code...

- Venki September 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

*piece* of code...

- Venki September 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define My_Sizeof(type) ((char*)((type*)0 +1) - (char*)(type*)0)

This works, I have checked on VC++ compiler

- Dilip September 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

the qn says you cannot use sizeof !!!

- priya June 07, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Will it work for My_Sizeof(map<int,int>)

- Anonymous April 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

None of the above macros would work if they are used with type 'void'

- Anonymous October 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice catch. But, I would argue the intention of getting the size of a void does not make much sense anyway.

- Anonymous October 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Really do they ask such rocket science :p

- Tanya January 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what something like this

int main()
{
char a;
int n;
if(n=((char*)(&a+1)-(char*)&a))
if(n==4)
printf("it is integer");
else if(n==1)
printf("it is char");
// and so on

return 0;
}


its working dear

- Learn Android: http://learnandroideasily.blogspot.in/ June 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

but u cant do it like this..u never know the data type can be a class object :P
and again they dnt asked u the data type..but just the size

- Aman August 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

#define sizeof(X) (((char *)((X *)0) + 1)) - ((char *)((X *)0)))

- ds December 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

too many parenthesis in the last post
cleaner one:

#define sizeof(X) ((char *)((X *)0 + 1) - (char *)((X *)0))

- Anonymous December 19, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define my_sizeof(p) ((char*)(&p+1) - (char*)(&p))

- Shri_code September 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Yahoo.. bleh.

- Anonymous September 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

The question explains why Yahoo had to use Bing to power its search results and why no one uses Yahoo mail.

- Mahesh September 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I see your point. I'm surprised by a lot of these ridiculous Yahoo interview questions.

- Anonymous September 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question might seem ridiculous, but it is a rather smart way to test if one understands pointer math and how C treats data types. And no, I dont work for Y!

- jake September 29, 2010 | 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