Lesson Set 10 - CS 1136 Lab 10 Arrays A one dimensional...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 1136 Lab 10 Arrays A one dimensional array is a data type in which a collection of places is given a name and the individual places are accessed by their position (index) within the collection. int [] numberList= new int[100]; In the above example, numberList is an array variable that contains the address of 100 integer variables. An individual integer variable within the array is accessed by giving the name of the array variable followed by its position (index). For example, numberList[0] accesses the first variable in the collection, and numberList[99] accesses the last variable in the collection. Note that the items in the collection are indexed from zero through the number in the collection minus 1. This is the reason why many programmers always begin for loops at zero. For example, the following code will assign zero to every variable in the array numberList. for (int index = 0; index < 100; index++) numberList[index] = 0; This technique can be used to initialize arrays at the beginning of the program; however, we can also initialize arrays like this: char [] charList = {‘a’, ‘b’, ‘c’, ‘d’}; We can leave out the 4 in the brackets on the previous statement, since we are explicitly telling the compiler how many elements charList contains. This can only be done when the array is declared.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern