PDA

View Full Version : Pascal Quiz 15




larswik
May 2, 2011, 01:09 AM
Please DON'T give me the answer on this problem but help me understand the question better. It is a take home quiz due tomorrow.

I don't know what a 'subscript' is that it refers to in this T or F Question.

Q: " An Array is a collection of elements of the same type referenced by a single name and one or more SUBSCRIPTS. The SUBSCRIPTS may be of different types as long as they are ordered. True or False"

Thanks,

-Lars



jiminaus
May 2, 2011, 01:30 AM
A subscript is the index you use to access the element of an array. In the C expression array[i], i is the subscript. In the C expression multidim[i][j], i and j are the subscripts. The term comes from mathematical matrices.

larswik
May 2, 2011, 01:49 AM
Thanks for that. The teacher likes to toss in trick questions and I almost want to say this question is TRUE except for the part that says "Subscripts may be of different types as long as they are ordered." Even if Subscripts are of a different type that is not going to effect the array type. If they are ordered the array will still be initialized, right?

That is not giving away the answer, but I am leaning towards True as the result for the answer for the question.

Sydde
May 2, 2011, 02:16 AM
What different types can a subscript be? For example, when I was learning BASIC (we use stone knives and bearskins in those days), and expression like "A(X)", where A was the array and X was the index, was verbalized as "A sub X". X was the subscript.

jiminaus
May 2, 2011, 02:24 AM
Sorry, I might have a caused a slight confusion by giving you examples of element access. The term applies equally (or more so in regards to you teacher's question) to how an array is declared.

In the Pascal examples from your Pascal Multi-Dimensional Arrays thread, consider the following Pascal declarations.

var
suit : array[1..4] of char;
rank : array[1..13] of char;
cards : array[1..4,1..13] of char;


In these declarations the stuff in square brackets can also be referred to as subscripts.

I think your teacher is asking you to think about the data types of these subscripts, particularly in regards to multi-dimensional arrays like the cards array above.

(BTW I actually don't know the answer to this question, because it's Pascal specific, I've forgotten 99% of Pascal.)

larswik
May 2, 2011, 02:29 AM
OK Guys and Gals, thanks again for the help. I will let you know tomorrow if I got it right or not.

-Lars