lecture22 Dynamic Arrays

lecture22 Dynamic Arrays - 1 Janice Regan, CMPT 128,...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Janice Regan, CMPT 128, February. 2007 CMPT 128: Introduction to Computing Science for Engineering Students Pointers and dynamic arrays Janice Regan, CMPT 128, February 2007 2 Review of arrays Recall automatic variables are those variables that are automatically allocated when the program runs Example of automatic variables: local variables declared with function scope Arrays with function scope are declared int myarray[23]; double yourarray[44]; Janice Regan, CMPT 128, February 2007 3 Automatic Arrays Array variables The identifier of the array is really a pointer to the first element in the array Automatic array myarray is a pointer to an int array (actually to the first element in the int array) yourarray is a pointer to a double array Memory allocated at compile time pointers to these automatic arrays are constant pointers (you cannot change where they point) Janice Regan, CMPT 128, February 2007 4 Array Variables Arrays elements are sequentially stored in memory Identifier of the array is a pointer to the beginning of the first element in the array An array variable is a kind of pointer variable! Example: int a[10]; int * p; p is a pointer variable, it can be modified to point anywhere a is a const pointer variable, it can only point to array a, its value (the address it contains) is constant and cannot be changed Janice Regan, CMPT 128, February 2007 5 Constant pointers Array variable int a[10]; a has more limitations than an ordinary pointer variable The type of a is const int * The const keyword indicates the value of the variable of a const type cannot be changed Identifier a must point to the location set aside for the automatic array a If we were allowed to change the address pointed to by a we would be pointing at something other than array a Janice Regan, CMPT 128, February 2007...
View Full Document

This note was uploaded on 05/18/2010 for the course CMPT 128 taught by Professor Regan during the Spring '08 term at Simon Fraser.

Page1 / 21

lecture22 Dynamic Arrays - 1 Janice Regan, CMPT 128,...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online