English

Explain how records are represented in memory using array, with suitable examples of four records and four fields. - Computer Science 1

Advertisements
Advertisements

Question

Explain how records are represented in memory using array, with suitable examples of four records and four fields.

Code Writing
Explain
Advertisements

Solution

Each individual piece of data is called a field. A file is a collection of similar records. A data item can also be a group item made up of smaller sub-items.

Consider a record whose structure is given below

     1. Employee
          2. Name
             3. First name
             3. Last name
          2. sex
          2. Address
              3. City
              3. Pincode
          2. Phone no.

To store this record in memory, linear arrays are used.

A separate linear array is maintained for each basic element of the record, such as First Name, Last Name, Sex, City, Pincode, and Phone Number.

The figure below illustrates how the above record is represented using parallel linear arrays.

Records are stored in memory using parallel linear arrays. For any index K, the elements First Name[K], Last Name[K], Sex[K], and so on correspond to the same record in the file; that is, the Kth record in the file.

Suppose we have 4 fields:

  • Roll No
  • Name
  • Class
  • Marks

And 4 records (students):

Roll No Name Class Marks
1 Amit 10 85
2 Neha 10 90
3 Rahul 10 78
4 Sneha 10 88

Representation in Memory using Parallel Arrays:

RollNo[ ] = {1, 2, 3, 4}

Name[ ] = {Amit, Neha, Rahul, Sneha}

Class[ ] = {10, 10, 10, 10}

Marks[ ] = {85, 90, 78, 88}

RollNo[2], Name[2], Class[2], Marks[2] → 3rd record (Rahul, 10, 78)

shaalaa.com
  Is there an error in this question or solution?
2024-2025 (July) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×