Submitted by euniceKANG on 04/03/2011 01:04 PM Flag This Paper
Join Now
IT/C++
Checkpoint
1/28/2010
* Define the following and provide an example of each:
-a pointer
-an array
* What is the difference between a one-dimensional array and a two-dimensional array?
Pointer – a pointer is a variable that stores the location in memory of another variable. It can also store objects. To declare a pointer variable you need to specify the type of variable it will point to and then you precede the variable name with an asterisk, for example:
int*ptr; -> integer
string*ptr; -> string
To point to a certain location in memory you must use the “&†notation. Say we have a file in the memory called NumberOfAccounts. In order to add this address to the pointer you would do something like this:
int*ptr;
ptr=&NumberOfAccounts;
Array – An array is similar to a pointer except it has multiple “compartments†which can be filled with a value. Generally arrays are used to contain large amounts of related items. To declare an array you first have to specify what type of array it is for example; say you want an array that stores prices of different DVD’s:
int DVD [5] -> declaration of array and number of slots within []’s
int DVD []= { 10.99, 14.99, 11.99, 21.99, 29.99}; -> placing information within those slots.
One-dimensional Array – An array that is set up like a list and requires only one subscript to identify a value contained in the array
Two-dimensional Array – An array that is set up like a table, with specific number of columns and rows.