A question from a Pupil

Hi, I’m currently studying computing on Scholar and one of the answers to a question I disagree with. The question is “a program stores the user IDs of 20 SCHOLAR users. Which of the following would be the most efficient way of storing this information?” and the possible answers are:
  • 20 integer variables
  • an array of integers
  • an array of strings
  • 20 string variables
Scholar says the answer is an array of strings, but why? I thought the answer would be an array of integers, as to log into Scholar you just use numbers. Please explain why it is an array of strings ?

Great question, if you look at your Scholar ID you will see it starts with a zero, Integer data types don’t store leading zeros. You were right to dismiss the separate variables, that leaves you with only the string array as a suitable data structure.

Lets look at the data representation at work. Here is a list of the memory requirements for every data type in VB. With VB6 which was in use with the class until just this year, you could not store a 9 digit number in a Integer, as it was Int16 and therefore limited to a maximum of 32,767. With the new express edition we have been using it can store up to a maximum of 2,147,483,647 but that does still store the leading zero. Try it in a calculator, enter your scholar ID and press equals, it will strip off the leading zero.

A tricky question to be sure.