Interview Question


Country: United States




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

sizeof returns size_t type which is unsigned integer. Comparison between int and unsigned int is unreliable. A warning is generated in gcc if compiled with -Wall. The solution is to cast a to int by (int)a in the for loop.

- suresh.amritapuri June 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I guess .. following is the issue
you have declared a preprocessor defination of 'a' which depends upon type of array[ ] which you have declared in your subsequent code

The value of preprocessor is substituted before the actual compilation begins. In this case the value of preprocessor can not be determined before compilation hence it takes d=0 while compiling and your for loop does not execute leaving a blank screen

- jain June 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

sizeof returns an unsigned integer so when u take d=-1 and cmpare it with the result d<=(a-3) initial value of d changes from -1 to an unsigned value that is 4294967295 which is not less so loop does execute.....

- shiv June 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is the correct logic. Whenever we compare signed and unsigned int without casting, the signed int is upgraded to unsigned int and treated as an unsigned int.

- Anonymous June 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

the value of the preprocessor is substituted before the actual compilation and here the value of the preprocessor cannot be determined hence it the loop doesn't execute !

- rishabh June 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if you run this program on turbo c++ it will simply print the array element from 23 to 99.how you r getting blank screen..??

- kuldeep June 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it is nt printing in turbo C++... how u got it?made ny correction??

- rockstar June 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i have added only getch() function before return 0.

- kuldeep June 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Dude ,it is macro which is preprocessor it reply a by sizeof statement and it work perfectly it give out put (7-3)=4 which prints (first 6 value of array)....use shortcut to see output altr+f5 ok.................................

- Satish Chauhan June 15, 2012 | Flag Reply


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