2-D Array Element Address Calculation – Computer Sir Ki Class

Login


Lost your password?

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

Login
[lwa]



Exam Questions-CBSE12D-2015-03B #CPP#5873    siteicon   siteicon  

Problem Statement - 2-D Array Element Address Calculation

A two dimensional array P[20] [50] is stored in the memory along the row with each of its element occupying 4 bytes, find the address of the element P[10] [30],if the element P[5] [5] is stored at the memory location 15000.

Solution

TC++ #5873

Loc(P[I][J]) along the row
 =BaseAddress+W [(I–LBR)*C+(J–LBC)]
(where C is the number of columns, LBR=LBC=0)
    LOC(P[5][5])
               = BaseAddress + W*[I*C + J]
         15000 = BaseAddress + 4*[5*50 + 5]
               = BaseAddress + 4*[250 + 5]
               = BaseAddress + 4*255
               = BaseAddress + 1020
   BaseAddress = 15000-1020= 13980
 LOC(P[10][30])= 13980 + 4*[10*50+30]
               = 13980 + 4*530
               = 13980 + 2120
               = 16100
OR
       LOC(P[10][30])
        = Loc(P[5][5])+ W[(I-LBR)*C+(J-LBC)]
        = 15000 + 4[(105)*50 + (30-5)]
        = 15000 + 4[ 5*50 + 25]
        = 15000 + 4 *275
        = 15000 + 1100
        = 16100
OR
(Where C is the number of columns and LBR=LBC=1) LOC(P[5][5])
   15000 = BaseAddress + W [(I-1)*C + (J-1)]
         = BaseAddress + 4[4*50 + 4]
         = BaseAddress + 4[200 + 4]
         = BaseAddress + 4 * 204
         = BaseAddress + 816
BaseAddress = 15000 816 = 14184
LOC(P[10][30])
         = 14184 + 4[(101)*50 + (301)]
         = 14184 + 4[9*50 + 29]
         = 14184 + 4[450 + 29]
         = 14184 + 4*479
         = 14184 + 1916
         = 16100


Share

CSKC| Created: 5-Jan-2019 | Updated: 10-Oct-2019|CBSE12D-2015






×
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