Arrays, Functions, and Pointers Flashcards

1
Q

what is the purpose of a pointer compared to a variable?

A

a pointer defaults to the first variable in an array
(ex. int numbers[2] = {10, 20};
int *p = numbers; // p points to the first element of the array)

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

what is the purpose of a function?

A

void changeValue(int *p) {
*p = 99;
}

int x = 10;
changeValue(&x);
printf(“%d”, x); // Prints 99, because we changed x via pointer

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

what is the purpose of an array?

A

void printArray(int arr[], int size) {
for (int i = 0; i < size; i++) {
printf(“%d “, arr[i]);
}
}

int numbers[3] = {1, 2, 3};
printArray(numbers, 3); // Passes the array to the function

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