CS Week 5- Arrays and Intro to Pointers Flashcards

1
Q

array

A

an ordered list of items of a given data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

element

A

each item in an array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

declaration of an array

A

dataType arrayName [numElements];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

index type

A

int type only

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

to check if index is valid

A

if (nth >= 1 && nth <= 5) { }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

iterate how many times through a loop

A

the size of the array that you should keep track up

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

array initilization

A

int myArray[3] = {5, 6, 7};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

array vs vector
declaration and accessed and differences

A

Array -
Declaration: int myList[#];
Accessed: myList[i];
Vector-
Declaration: vector<int> myList(#)
Accessed: myList.at(0);</int>

Arrays have simpler syntax but do not have .size() feature
Vectors are safer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

an array as a paramter

A

uses the [], but argument does not
passes in an array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

reversing an array

A

loop numElements/2 times
tempVal = a[i];
a[i] = a[numElements - 1- i];
a[numElements - 1-i] = tempVal;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

two dimensional array

A

int myArray [R][C]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

row major order

A

compiler maps 2-dimensional array elements to one-dimensional memory, each row following the previous row

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

two-dimensional array initialization

A

int nums [2][3] = { {2,4,6}, {5,6,7} };
Or to make it more visible
int nums [2][3] = {
{2, 4, 6},
{5, 6, 7}
};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

access row n and column m

A

array[n-1][m-1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

pointer

A

a variable that holds a memory address (rather than holding data)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what does the data type of a pointer mean

A

the type of address that is held in the pointer

17
Q

declare and initialize it

A

int* pointer = &someVar;

18
Q

dereference operator

A

*
is prepended to a pointers variable name to retrieve the data to which the pointer variable points

19
Q

null pointer

A

When a pointer is declared, the pointer variable holds an unknown address until the pointer is initialized
Null means nothing
int* pointer = nullptr;

20
Q

check if null

A

in notes

21
Q

change the value of the variable that the pointer is pointing to

A

*p = 888;

22
Q

use/cout the pointer/the value the pointer is poitning to

A

cout &laquo_space;*p;

23
Q

other ways to dereference a pointer

A

*p = 44;

p[0] = 444;
p[-1]
go to where p is pointing and advance 0/-1 steps

p = p + 1
*p = 555;

*(p+1) = 8888;

24
Q

other ways to initialize a pointer

A

int* q = p + 5;
int* q = A + 5;
int* q = &(A[5]);
int* q = A;

25
Q

double pointer and const

A

int** pp = &p
pp points to the same place as p

int * const * const what;
-a const pointer to a const pointer to an int (what)
-can change the value of what you are pointing to

const int * const * const what;
can not change what the pointer is pointing to

26
Q

K, Meg, Gig, Tera

A

K = 2^10
Meg = 2 ^10 K = 2 ^20
Gig = 2 ^10 M = 2 ^ 30
Tera = 2 ^ 10 G = 2 ^ 40

27
Q

passing in an array or pointer into a funciton

A

int A[]

int* A
- no need for reference because * is one kinda

int* A, unsigned n;
let people know what passing in
n = offset if A is a pointer, size of pointer is a collection of data