Finding relative address in 2D Array – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-CBSE12D-2016-03B #CPP#6167    siteicon   siteicon  

Problem Statement - Finding relative address in 2D Array

T[20][50] is a two dimensional array, which is stored in the memory along the row with each of its element occupying 4 bytes, find the address of the element T[15][5], if the element T[10][8] is stored at the memory location 52000.

Solution

TC++ #6167

Loc(T[I][J])
       =BaseAddress + W [( I – LBR)*C + (J – LBC)]
(where
W=size of each element = 4 bytes,
R=Number of Rows=20, C=Number of Columns=50)
Assuming LBR = LBC = 0

LOC(T[10][8])
      52000 = BaseAddress + W[ I*C + J]
      52000 = BaseAddress + 4[10*50 + 8]
      52000 = BaseAddress + 4[500 + 8]
      52000 = BaseAddress + 4 x 508
BaseAddress = 52000 2032
            = 49968
LOC(T[15][5])= BaseAddress + W[ I*C + J]
             = 49968 + 4[15*50 + 5]
             = 49968 + 4[750 + 5]
             = 49968 + 4 x 755
             = 49968 + 3020
             = 52988
OR
Loc(T[I][J])
     =ReferenceAddress + W [( I – LR)*C + (J – LC)]
(where 
W=size of each element = 4 bytes,
R=Number of Rows=20, C=Number of Columns=50)
ReferenceAddress= Address of given cell T[10][8]=52000
LR = Row value of given cell = 10
LC = Column value of given cell = 8
LOC(T[15][5])= LOC(T[10][8]) + 4[(15-10)*50 + (5-8)]

LOC(T[15][5]) = 52000 + 4[5*50 + (-3)]
              = 52000 + 4[250-3]
              = 52000 + 4 x 247
              = 52000 + 988
              = 52988


Share

CSKC| Created: 10-Jan-2019 | Updated: 10-Oct-2019|CBSE12D-2016






×
Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Multi-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues


Back