GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 402 of 453    Print  
difference b/w a[i] and i[a]
Is there any relation between a[i] and i[a] while using arrays..can anyone help me with this....


  
Total Answers and Comments: 8 Last Update: June 09, 2008     Asked by: rosuuuuu1010 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: vijoeyz
 
They are same.  a[i] is treated as *(a+i), and i[a] is *(i+a).  And from the rule of associativity, you can see that both expressions will yield to the same result.

Thanks,
Vijay Zanvar
http://faq.zanvar.in

Above answer was rated as good by the following members:
RoMBiN
February 04, 2008 04:24:15   #1  
chetan arora Member Since: February 2008   Contribution: 1    

RE: difference b/w a[i] and i[a]
These are two different way of refering the array element. eg arr[2] and 2[arr] both will refer to third element in array.
 
Is this answer useful? Yes | No
February 08, 2008 01:02:18   #2  
vanavill Member Since: February 2008   Contribution: 7    

RE: difference b/w a[i] and i[a]
I go with chetan
it is different way of array.both a[i]&i[a] note the third element.

 
Is this answer useful? Yes | No
February 22, 2008 03:19:16   #3  
vijoeyz Member Since: September 2007   Contribution: 3    

RE: difference b/w a[i] and i[a]
They are same. a[i] is treated as *(a+i) and i[a] is *(i+a). And from the rule of associativity you can see that both expressions will yield to the same result.

Thanks
Vijay Zanvar
http://faq.zanvar.in

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
April 09, 2008 08:01:40   #4  
pavan.mustyala Member Since: April 2008   Contribution: 7    

RE: difference b/w a[i] and i[a]

Actually there is no difference b/w both representations.

Both represent the value at ith location of the array.The a[i] is accessesd as *(a + i)) and i[a] as *(a + i). So conceptually both representations are same.


 
Is this answer useful? Yes | No
April 09, 2008 08:52:58   #5  
ashoksurati Member Since: April 2008   Contribution: 13    

RE: difference b/w a[i] and i[a]
There is no difference b/w a[i] and i[a] System can understand boyh as *(a+i) *(i+a).

Let us take an eg:let address location of array named by a is "100" and a is an int type array let " i " is the 3rd eliment i.e i 2.then a[i] *(100+2(4bytes))( *(104) which is starting location of 3rd eliment's of array.

Now i[a] *(2(4bytes)+100) (*(104)) which is also represents the same 3rd eliment's starting address location. so both are same.

Thank U.

 
Is this answer useful? Yes | No
April 09, 2008 11:02:34   #6  
Bharathiponaganti Member Since: April 2008   Contribution: 1    

RE: difference b/w a[i] and i[a]
I go to with ashoksurati
Both a[i] and i[a] are shows internal address location of that array eliment.

 
Is this answer useful? Yes | No
May 29, 2008 00:36:09   #7  
paragmalshe Member Since: May 2008   Contribution: 5    

RE: difference b/w a[i] and i[a]
there is no difference in compilation perspective
both are internally converted as *(a+i) or *(i+a) which means the same thing

 
Is this answer useful? Yes | No
June 09, 2008 07:20:56   #8  
jintojos Member Since: May 2008   Contribution: 29    

RE: difference b/w a[i] and i[a]
Bath a[i] and i[a] are same.....the variable name 'a' contains the basic address of the array.so a[i] means base address + index 'i' and also i[a] means base address + index 'i'
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

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

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

Page copy protected against web site content infringement by Copyscape