11 Vote

Difference between Array and Record

Question by Guest | 2016-10-31 at 19:09

At the moment, I am learning programming at school and I am just wondering what the difference between an array and a record might be.

For me, both are types of data structures which can be used to store multiple values. So, why do we need two different terms for the same idea?

ReplyPositiveNegative
0Best Answer0 Votes

Indeed, an array as well as a record are providing the possibility to store data in it. However, there is one important difference: an array can only be used for storing elements of the same type, while a record can contain multiple elements of a different type.

Here is a small example:

intArr = array of integer;

strArr = array of string;

recPerson = record
  ForeName, SurName: string;
  BirthDay: TDateTime;
  Income: integer;
end;

arrPersons = array of recPerson;

Here we have first declared two different arrays. The array intArr can only hold numbers (integer type), the array strArray only text (string type). After that, you can find the declaration of the record recPerson. This record can not only contain only numbers are only text, but lots of different types such as strings, a date and a number. arrPersons is an array that can only consist of elements of the type recPerson, so this array-record-combination is consisting of both concepts.

I hope that this example could clarify the difference between array and record.
2016-11-01 at 18:38

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.