Professional Documents
Culture Documents
JAVA 2
Quarter 3 – Module 2:
TWO – DIMENSIONAL ARRAYS AND POINTERS
Development Team:
Writer: Randy T. Mercado
Reviewer: Marife P. De Castro
Layout: Paulo Stephen Cadawas
Management: Dr. Edwin T. Casila, MCL – Principal
Christian D. Manalansan – President
©2020 Mind and Integrity College, Inc. All Rights Reserved Page 1 of 11
Dear Parents,
Mind and Integrity College, Inc. is one with every Filipino family in coping with the
demands of our modern times amidst the threat of COVID-19 pandemic.
Thank you in advance for being one with us! Together, let us envision that, by the
end of this school year, we will see your child as one responsible young person with a
heart and mind for humanity, for nature, for the country, and for God.
Dear Learner,
This is our gift to you. The school initiated the distribution of Self-Learning
Modules (SLM) that will help you keep up with the lesson whether you opted for online,
modular, or blended learning as a modality.
Please take time to read and do the activities in these SLM as if you are reporting
in school. Set a regular study schedule for you as much as possible, but keep in mind
that these SLM will enable you to learn at your own pace. If you do not understand a
lesson, the SLM would not mind you flipping back the pages repeatedly for review. Also,
remember to keep in touch with your teachers. Send them a message through your
online sessions or write them a note as you do your modular activities.
We wish you good luck in your studies, and we hope that you will remain happy
and enthusiastic in learning!
©2020 Mind and Integrity College, Inc. All Rights Reserved Page 2 of 11
What This Module is About
Fast and efficient processing of two-dimensional arrays is essential in land-change modeling
because of the substantial computational effort expended by some computer land change models in
processing raster-graphic images and other two-dimensional arrays. Elapsed, wall-clock runtimes
for spatially explicit land-change models often span days or weeks, so improvements in the speed
and efficiency of a land-change model’s executable computer code can reduce its runtime by hours
or even days. The speed of execution can make the difference between a model that is fast enough
to be used and one that is not. Computational speed and efficiency in array processing are
fundamental, threshold concerns in land-change modeling and other areas of scientific
computation.
NOTE: Prepare yellow pad papers where you would write all your outputs for this
module. Do not forget to label your works properly corresponding to the title of each
activity. Also, please label your work with module number and module title. Do not forget
to write your name, section and the date of first entry.
Make sure to clip/staple your works so that they will not easily be separated. It is advised
to take down notes about the important information from each lesson because of the
modules will be returned at the end of every week. Please do not write anything on
module.
©2020 Mind and Integrity College, Inc. All Rights Reserved Page 3 of 11
What’s In This part connects previous lesson with that of
the current one.
©2020 Mind and Integrity College, Inc. All Rights Reserved Page 4 of 11
Lesson 1: TWO – DIMENSIONAL ARRAY
INTRODUCTION
Thus far, you have used one-dimensional arrays to model linear collections of elements. You
can use a two-dimensional array to represent a matrix or a table. For example, the following table
that describes the distances between the cities can be represented using a two - dimensional array.
What Is It
TWO – DIMENSIONAL ARRAY
You can use a two-dimensional array to represent a matrix or a table.
Occasionally, you will need to represent n-dimensional data structures. In Java, you can
create n-dimensional arrays for any integer n.
The simplest form of the multidimensional array is the two-dimensional array. A two-dimensional
array is, in essence, a list of one-dimensional arrays. To declare a two-dimensional integer array of
size x,y, you would write something as follows:
Where type can be any valid C++ data type and arrayName will be a valid C++ identifier. A two-
dimensional array can be think as a table, which will have x number of rows and y number of
columns. A 2-dimensional array a, which contains three rows and four columns can be shown as
below:
©2020 Mind and Integrity College, Inc. All Rights Reserved Page 5 of 11
Thus, every element in array a is identified by an element name of the form a[ i ][ j ], where a is the
name of the array, and i and j are the subscripts that uniquely identify each element in a.
Multi - dimensioned arrays may be initialized by specifying bracketed values for each row.
Following is an array with 3 rows and each row have 4 columns.
The nested braces, which indicate the intended row, are optional. The following initialization is
equivalent to previous example:
An element in 2-dimensional array is accessed by using the subscripts, i.e., row index and column
index of the array. For example:
The above statement will take 4th element from the 3rd row of the array. You can verify it in the
above diagram.
©2020 Mind and Integrity College, Inc. All Rights Reserved Page 6 of 11
When the above code is compiled and executed, it produces the following result:
As explained above, you can have arrays with any number of dimensions, although it is likely that
most of the arrays you create will be of one or two dimensions.
What’s New
©2020 Mind and Integrity College, Inc. All Rights Reserved Page 7 of 11
Lesson 2: POINTERS
What I Need to Know
INTRODUCTION
What Is Pointer?
Variable in a program is something with a name, the value of which can vary. The way the compiler
and linker handles this is that it assigns a specific block of memory within the computer to hold the
value of that variable.
DEREFERENCING
Dereferencing means taking away the reference and giving you what it was actually referring
to.
Dereferencing is used to access or manipulate data contained in memory location pointed to by a
pointer. *(asterisk) is used with pointer variable when dereferencing the pointer variable, it refers
to variable being pointed, so this is called dereferencing of pointers.
int bar = *foo_ptr;
*foo_ptr = 42; // set foo to 42 which is also effect bar = 42
©2020 Mind and Integrity College, Inc. All Rights Reserved Page 8 of 11
Difference Between & and *
& is the reference operator and can be read as "address of“
* is the dereference operator and can be read as "value pointed by"
©2020 Mind and Integrity College, Inc. All Rights Reserved Page 9 of 11
When the above code is compiled and executed, it produces result something as follows:
©2020 Mind and Integrity College, Inc. All Rights Reserved Page 10 of 11
What’s New
ACTIVITY 2: What is the output of the given source code below? Write your answer on your yellow
pad paper.
References
“Chapter 7: Multi – dimensional Array”
https://www2.southeastern.edu/Academics/Faculty/kyang/2010/Fall/CMPS161/ClassNotes/CM
PS161ClassNotesChap07.pdf
“C++ Pointers”
https://www.tutorialspoint.com/cplusplus/pdf/cpp_pointers.pdf
©2020 Mind and Integrity College, Inc. All Rights Reserved Page 11 of 11