Series: Subject: Topic:
Question: 118 of 126

int x[] = { 1, 4, 8, 5, 1, 4 };
int *ptr, y;
ptr = x + 4;
y = ptr - x;
What does y in the sample code above equal?

A. -3
B. 0
C. 4
D. 4 + sizeof( int )

Asked by: Interview Candidate | Asked on: Jul 25th, 2005
Showing Answers 1 - 5 of 5 Answers
Vijaya Bhaskar M

Answered On : Jul 24th, 2005

The correct choice is D . since in the program it is dealing only with the address not with the values present at the address. so it will add the 4 to the size of interger.

Login to rate this answer.

Answered On : Oct 17th, 2006

The correct answer is 'C' ...... As the value of ptr-x will always be in terms of "how many integer fields the two pointer differ".....Moreover, answer can never be 'D', as it says 4 + sizeof(int), while the actual address should be 4*sizeof(int)...

Yes  1 User has rated as useful.
Login to rate this answer.

Answered On : Nov 11th, 2006

Answer is -3

Login to rate this answer.

Answered On : Nov 26th, 2006

  int x, *ptr;      *ptr = &x;

Login to rate this answer.

Answered On : Jun 9th, 2008

View all answers by anu1985


Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions



twitter fb Linkedin GPlus RSS


Interview Question

 Ask Interview Question?


Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.