SlideShare a Scribd company logo
1 of 4
Download to read offline
CS111 Lab
arrays
Instructor: Michael Gordon
Why Use Arrays
 Arrays

are used for dealing with sets of
data elements that are of the same type.
 You can have an array of ints, doubles,
chars, strings, etc.
 Arrays mean not having to create
separate variables/names for each
element.
 Arrays are contiguous spaces in memory.
How do we use Arrays
 int


Declares an array of size 5

 int


grades[5];
grades[5] = {1, 2, 3, 4, 5};

Assigns values to each of the elements

 grades[0]


Assigns value of 100 to the first element.

 grades[4]


= 100;

= 10;

Assigns value of 10 to the last element.
Limits and Advice
 Arrays

must have a variable type.
 The first element of an array is number 0.


The last is: size-1;

 For

now, we cannot create an array with
a variable size. (ex: int array[n];)
 Unassigned elements should not be
assumed to be zero.
 Use a separate for loop for each task.

More Related Content

What's hot

Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 
Cso gaddis java_chapter8
Cso gaddis java_chapter8Cso gaddis java_chapter8
Cso gaddis java_chapter8
mlrbrown
 

What's hot (20)

C++ arrays part1
C++ arrays part1C++ arrays part1
C++ arrays part1
 
Array
ArrayArray
Array
 
OOPs with java
OOPs with javaOOPs with java
OOPs with java
 
Insertion operation in array(ds)
Insertion operation in array(ds)Insertion operation in array(ds)
Insertion operation in array(ds)
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structures
 
Array operations
Array operationsArray operations
Array operations
 
String
StringString
String
 
Sorting
SortingSorting
Sorting
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Array
ArrayArray
Array
 
Data structures Lecture 5
Data structures Lecture 5Data structures Lecture 5
Data structures Lecture 5
 
Id3 algorithm
Id3 algorithmId3 algorithm
Id3 algorithm
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
R data types
R data typesR data types
R data types
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Learn Java Part 9
Learn Java Part 9Learn Java Part 9
Learn Java Part 9
 
Cso gaddis java_chapter8
Cso gaddis java_chapter8Cso gaddis java_chapter8
Cso gaddis java_chapter8
 
Java arrays (1)
Java arrays (1)Java arrays (1)
Java arrays (1)
 
Java
JavaJava
Java
 

Viewers also liked (8)

While loops
While loopsWhile loops
While loops
 
Arrays, continued
Arrays, continuedArrays, continued
Arrays, continued
 
Strings1
Strings1Strings1
Strings1
 
Strings2
Strings2Strings2
Strings2
 
Introduction to Computer Science 111 Lab
Introduction to Computer Science 111 LabIntroduction to Computer Science 111 Lab
Introduction to Computer Science 111 Lab
 
Millennial white paper
Millennial white paperMillennial white paper
Millennial white paper
 
貧窮
貧窮貧窮
貧窮
 
Strings
StringsStrings
Strings
 

Similar to Arrays

Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
dfsdg3
 

Similar to Arrays (20)

Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
javaarray
javaarrayjavaarray
javaarray
 
Generative Coding Lecture notes using coding
Generative Coding Lecture notes using codingGenerative Coding Lecture notes using coding
Generative Coding Lecture notes using coding
 
Array
ArrayArray
Array
 
Chapter-Five.pptx
Chapter-Five.pptxChapter-Five.pptx
Chapter-Five.pptx
 
Arrays
ArraysArrays
Arrays
 
2 arrays
2   arrays2   arrays
2 arrays
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
INDIAN INSTITUTE OF TECHNOLOGY KANPUR ESC 111M Lec12.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPUR ESC 111M Lec12.pptxINDIAN INSTITUTE OF TECHNOLOGY KANPUR ESC 111M Lec12.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPUR ESC 111M Lec12.pptx
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Array lecture
Array lectureArray lecture
Array lecture
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Arrays
ArraysArrays
Arrays
 
Week6.ppt
Week6.pptWeek6.ppt
Week6.ppt
 
Basics of array.pptx
Basics of array.pptxBasics of array.pptx
Basics of array.pptx
 
Arrays
ArraysArrays
Arrays
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
 

More from Michael Gordon (11)

Raspberry Pi presentation for Computer Architecture class
Raspberry Pi presentation for Computer Architecture classRaspberry Pi presentation for Computer Architecture class
Raspberry Pi presentation for Computer Architecture class
 
Introduction to Linux, Pico, G++
Introduction to Linux, Pico, G++Introduction to Linux, Pico, G++
Introduction to Linux, Pico, G++
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
Functions
FunctionsFunctions
Functions
 
Shape logic 1
Shape logic 1Shape logic 1
Shape logic 1
 
For loops
For loopsFor loops
For loops
 
If statements
If statementsIf statements
If statements
 
Arithmetic
ArithmeticArithmetic
Arithmetic
 
Variables
VariablesVariables
Variables
 
Output
OutputOutput
Output
 
Word cloud
Word cloudWord cloud
Word cloud
 

Arrays

  • 2. Why Use Arrays  Arrays are used for dealing with sets of data elements that are of the same type.  You can have an array of ints, doubles, chars, strings, etc.  Arrays mean not having to create separate variables/names for each element.  Arrays are contiguous spaces in memory.
  • 3. How do we use Arrays  int  Declares an array of size 5  int  grades[5]; grades[5] = {1, 2, 3, 4, 5}; Assigns values to each of the elements  grades[0]  Assigns value of 100 to the first element.  grades[4]  = 100; = 10; Assigns value of 10 to the last element.
  • 4. Limits and Advice  Arrays must have a variable type.  The first element of an array is number 0.  The last is: size-1;  For now, we cannot create an array with a variable size. (ex: int array[n];)  Unassigned elements should not be assumed to be zero.  Use a separate for loop for each task.