Home › SparkNotes › Computer Science Study Guides › Review of Pointers › Review Test
This page requires JavaScript, which you don't seem to have. Please try a different browser.
Scroll through the page to review your answers. The correct answer is highlighted in green. Your incorrect answers (if any) are highlighted in red. If you'd like to take the test over again, click the reset button at the end of the test.
In C arrays and pointers can always be used interchangeably.
In C, a string is equivalent to a pointer to a character.
In C, an array with ten elements is indexed from 1 through 10.
If str is a character pointer variable that holds the string "Read SparkNotes", then str[3] refers to the character 'a'.
In C, when an array is passed to a function, only the address of the array is passed to the function.
In C, a parameter is passed by reference when the address of a variable is passed to the function.
The declaration typedef int *i_ptr; creates a variable called i_ptr which can hold the addresses of integers.
The function malloc can be used to dynamically allocate memory for an array.
If rec is a struct variable and number is a field of the structure, then the number field of rec is expressed as rec->number.
Let p be a pointer to an integer and i be an integer variable. Which of the following is not a correct assignment?
In C, the end of a string is marked by
A segmentation fault occurs when:
The expression sizeof(int) refers to
What is the output of the following program?
int main () { int i, j, *p, *q; p = &i; q = &j; *p = 5; *q = *p + i; printf("i = %d, j = %d\n", i, j); return 0; }
void spark(int A[]) { printf("A[0] = %d, A[1] = %d, A[2] = %d\n", A[0], A[1], A[2]); A[1] = 0; } int main() { int A[3] = {1, 2, 3}; spark(A); printf("A[0] = %d, A[1] = %d, A[2] = %d\n", A[0], A[1], A[2]); return 0; }
A[0] = 1, A[1] = 2, A[2] = 3 A[0] = 1, A[1] = 2, A[2] = 3
A[0] = 1, A[1] = 2, A[2] = 3 A[0] = 1, A[1] = 0, A[2] = 3
A[0] = 1, A[1] = 0, A[2] = 3 A[0] = 1, A[1] = 0, A[2] = 3
A[0] = 0, A[1] = 0, A[2] = 0 A[0] = 0, A[1] = 0, A[2] = 0
void add_10(int a, int *p) { *p = a + 10; } int main() { int x = 2, y = 6; add_10 (x, &x) ; printf("x = %d, y = %d\n", x, y) ; add_10 (x, &y) ; printf("x = %d, y = %d\n", x, y) ; return 0; }
x = 12, y = 6 x = 12, y = 22
x = 2, y = 6 x = 2, y = 6
x = 8, y = 6 x = 8, y = 14
x = 12, y = 6 x = 12, y = 18
In most languages and on most computer systems, NULL is what value?
int *x; and int* x; both have the same effect.
Functions aren't basic data types, so you can't have pointers to them.
A memory leak happens when we allocate memory using malloc() and then free it using free().
What does the following function do?
void mystery(int* a, int* b) { if (*a > *b) { int temp = *a; *a = *b; *b = temp; } }
A dangling pointer is a pointer which points to a thing in memory which has been free'd or has vanished for some other reason. Dangling pointers are bad because you don't know what's at that spot any longer. In the following code, what is the dangling pointer?
int* y = malloc(sizeof(int)); int* z = y; free(z);
Two or more memory locations can have the same address.
A pointer variable can point to floating-point values only.
An array can be used as a constant pointer.
Pointers can store the addresses of which data structures?
What is the name of the & operator?
Which of the following is not a use of the * operator?
In the following code
int spark; int *p; p = &spark; p += 2;
Which of the following are equivalent, assuming that arr is an integer array and that ptr is an integer pointer pointing to the start of the array?
What data structure, in words, does the following declaration declare? float * measures[250];
Given the following variable and array declarations
float arr[] = {1.0, 2.1, 3.2, 4.3, 5.4, 6.5, 7.6, 8.7}; float * ptr1, *ptr2;
What does the variable i contain after the following code executes?
int i = 17; int *p = &i; *p = 98;
What, if anything, is wrong with the following code?
void *p; p = (float*) malloc(sizeof(float)); *p = 7.89;
After the following code:
int *p; int i; int k; i = 63; k = i; p = &i;
int i = 23; int j = 72; int *p1; int *p2; p1 = &i; p2 = &j; *p1 = *p2;
int i = 2; int k = 4; int *p1; int *p2; p1 = &i; p2 = &k; p1 = p2; *p1 = 6; *p2 = 8;
int i = 2; int k = 4; int* p1; int* p2; p1 = &i; p2 = &k; *p1 = *p2; *p1 = 6; *p2 = 8;
Given the following array declaration and function definition
void spark(int z[]); int x[10];
After this code executes
int arr[10]; int i; i = &arr[9] - arr;
In a C/C++ program, the main() function is actually defined as int main(int argc, char **argv); What is argv?
What is 0xabcd in binary?
int a = 54; int *p = (int *)malloc(1); *p = 72; p = &a;
Remember me
Liven up your study sesh with one of these playlists!
Enjoy the tunes! This expertly-crafted playlist is brought to you by
Chris Pine and Zoe Saldana heat up the red carpet!
Auntie SparkNotes can help!
Click here for simple, sexy makeup tricks!
See every single look from the Met Gala!
We already dib'sed Genghis Khan.
Travel back in time!
From super cute to super bad!
What do you think?
When you don't look like J-Law.
What did Star Trek get wrong?
Get Our FREE NOOK Reading Apps