GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 394 of 453    Print  
What is the relation between array name and an element number.

  
Total Answers and Comments: 4 Last Update: June 09, 2008     Asked by: varun 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 17, 2007 13:34:53   #1  
Manohar        

RE: What is the relation between array name and an ele...
Array name is the pointer to the first element of the array.
when you say *aiNumber it will give you value of first element of the array.
*(aiNumber+3) is same as aiNumber[3]...

 
Is this answer useful? Yes | No
November 19, 2007 01:13:22   #2  
baseersd Member Since: June 2007   Contribution: 34    

RE: What is the relation between array name and an ele...
Array name is nothing but
1 ) The address of the array
2 ) Address of the first element of the array.

Element number is the offset of the element. Which means to get the element of the array we have to increment the base address of the array with the offset.

Here is an example.

int arr[5] {10 20 30 40 50};

arr will hold the address of the array.
*arr arr[0];

Here to access the first number of the array no need to increment. Hence the offset if zero.

Similarly to access 3rd element
arr[2].

 
Is this answer useful? Yes | No
November 20, 2007 18:38:12   #3  
Joe        

RE: What is the relation between array name and an ele...

The relationship between an array element and the elements index number is as follows.

1. The array name by itself is a constant pointer to the first element of the array.

So if you have this int iary[4] { 10 22 4 17 } then 'iary' is a constant

pointer to the value 10 so *iary '10';

2. An array elements index represents an offset in the array to that element.

So if you have an element index of 2 for the above array (iary) then

iary[2] 4. Notice it does not equal 22. In 'c' array indexing starts at 0.

Because array indexing starts at 0 iary[0] 10 iary[1] 22
iary[2] 4 and iary[3] 17.


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

RE: What is the relation between array name and an element number.
Array name is the base address of the aaray. By using this base address we can refer to the array elements. that is a[0] means "base address + 0th" element. that is array element number is the distence from the base address to the specified data
 
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 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape