GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Placement Papers  >  Oracle  >  Technical
Go To First  |  Previous Question  |  Next Question 
 Technical  |  Question 9 of 126    Print  

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 )


  
Total Answers and Comments: 5 Last Update: June 09, 2008   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by:
 
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)...


Above answer was rated as good by the following members:
adeshgupta
July 24, 2005 11:18:29   
Vijaya Bhaskar M        

RE: int x[] = { 1, 4, 8, 5, 1, 4 };int *ptr, y;ptr = x + 4;y = ptr - x;What does y in the sample code ab...
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.
 
Is this answer useful? Yes | No
October 17, 2006 08:14:40   
       

RE: int x[] = { 1, 4, 8, 5, 1, 4 };int *ptr,...
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)...

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
November 11, 2006 07:33:39   
manoj        

RE: int x[] = { 1, 4, 8, 5, 1, 4 };int *ptr,...
answer is -3
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 2Overall Rating: -2    
November 26, 2006 22:54:40   
Thanom        

what is wrong with this
int x *ptr;
*ptr &x;

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
June 09, 2008 15:22:38   
anu1985 Member Since: May 2008   Contribution: 11    

RE: 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. -3B. 0C. 4D. 4 + sizeof( int )
ptr &x[5]
ptr (x+4)
y (x+4)-(x+0);
y 4

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape