Pascal Quiz 15

Discussion in 'Mac Programming' started by larswik, May 1, 2011.

  1. macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    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
     
  2. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    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.
     
  3. thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    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.
     
  4. macrumors 68000

    Sydde

    Joined:
    Aug 17, 2009
    #4
    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.
     
  5. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #5
    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.)
     
  6. thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #6
    OK Guys and Gals, thanks again for the help. I will let you know tomorrow if I got it right or not.

    -Lars
     

Share This Page