CSC209: arrays & pointers

0.0(0)
studied byStudied by 2 people
0.0(0)
full-widthCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/13

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

14 Terms

1
New cards

type in array

all elements in an array need to be the same type

2
New cards

allocation of arrays

need to allocate space for all the elements in the array

eg. an array with 4 int elements would be initialized like int arr[4];

3
New cards

what happens when you call arr?

you receive a pointer to the first element of the array

4
New cards

how to instantiate an array?

int arr[3] = {0, 1, 2};

it is cleaner to instantiate all the elements at the beginning and this is the only time you can do so, afterwards you must instantiate each element individually

5
New cards

size of array

an array cannot change size, if you need a larger array you would need to make a new one and copy all the elements into the new array from the original one

6
New cards

how to iterate through an array?

once we know the address of where the array starts, and the size of each element, we can calculate the address of each element

we rely on this fact when we use indexes to access elements of the array

7
New cards

big issue with arrays

C does not check that an array access is within the bounds of the array

8
New cards

what is a pointer?

stores the address of a variable

9
New cards

how to declare a pointer?

int *pt;

this will create a pointer that points at an integer

10
New cards

how to store an address in a pointer?

int i;
int *pt;
pt = &i;

using “&” allows you to access the address of a variable

11
New cards

how to access the value that is pointed to by a pointer?

int i = 209;
int *pt = &i;
printf("Value pointed to by pt: %d\n", *pt);

using “*” in this context is called dereferencing a pointer

i and *pt are aliases

12
New cards

how do changes persist?

when we pass a pointer to the first element of an array rather than passing a copy of the array

13
New cards

arithmetic on a pointer

when we use the + operator on a pointer, its behaviour depends on the type of the pointer

14
New cards

pointer to pointer

to initialize and dereference we need to use **

Explore top flashcards

October exam
Updated 465d ago
flashcards Flashcards (32)
10/6
Updated 218d ago
flashcards Flashcards (62)
PSCH 262 Final Exam
Updated 634d ago
flashcards Flashcards (110)
WWII
Updated 4d ago
flashcards Flashcards (35)
October exam
Updated 465d ago
flashcards Flashcards (32)
10/6
Updated 218d ago
flashcards Flashcards (62)
PSCH 262 Final Exam
Updated 634d ago
flashcards Flashcards (110)
WWII
Updated 4d ago
flashcards Flashcards (35)