Skip to main content
To Get All Information of Sarkari Jobs | Results | Admit Card | And courses ,Internships then CLICK HERE

Base Address And Formula Of Calculating Address Of Array Element-:


The first address of array is known as base address.The array name is a symbolic reference to the address to the first byte of an array i.e.,when we use the array name we are actually referring the first byte of array.
for example-: If there is array whose name is num,then if we write statement printf("%d",num); - then it will give output as the base address of that array.

Calculating The Address Of Array Element-:
  • As we know that the array name is a symbolic reference to the address of the first byte of an array.So,when we use the array name we are actually referring to the first byte of the array.
  • Now here the question arises how the compiler knows where an individual element of the array is located in the memory.
  • The subscript or the index represents the offset from the beginning of the array to the element being reffered with just array name and index,compiler can calculate the address of any element in the array,the formula for doing this calculation is as follow-:
A[K]=BA[A]+W[K-lower bound] 
Where;
A-: is the array.
K-: is the index of element for which we have to calculate the address.
BA-:base address
W-: is the word size of one element in memory
lower bound-: is the index of the first element in the array.
Q- Consider the following array,calculate the address of mark[4],if the base address is 1000,
                   int mark[ ]={99,67,78,56,88,90,34,85};
=> we know that,
                A[K]=BA[A]+W[K-lower bound] 
here,
               mark[4]=1000+2(4-0)
               mark[4]=1000+8
               mark[4]=1008.
                            Watch The Video Below

ads



Comments

Post a Comment

Please do not enter any spam link in the comment box.


Download The Book "Let Us C" By Yashavant P.Kanetkar,Click The Below Button

-->Email Subscription

Enter Your Email Address:-

Delivered by FeedBurner

Copyright © 2020 TechProgramiz|All Right Reserved|Made By-: Sudarshan Pandey