Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
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

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
A subscript is the index you use to access the element of an array. In the C expression array, i is the subscript. In the C expression multidim[j], i and j are the subscripts. The term comes from mathematical matrices.
 

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
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

macrumors 68030
Aug 17, 2009
2,552
7,050
IOKWARDI
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

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
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.
Code:
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

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
OK Guys and Gals, thanks again for the help. I will let you know tomorrow if I got it right or not.

-Lars
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.