C Pointers Quiz

Questions: 16 · 10 minutes
1. If p has type int *, which statement idiomatically allocates enough space for five int elements?
Scale by the pointed-to type: p = malloc(5 * sizeof *p);
Request only five bytes: p = malloc(5);
Use the size of the pointer: p = malloc(sizeof p);
Use five pointer-address sizes: p = malloc(5 * sizeof &p);
2. Given the declaration int n;, which operation obtains the memory address of n?
Dereference n with *n
Apply array notation with n[]
Measure the object using sizeof n
Apply the address operator as &n
3. A function is declared void swap(int *x, int *y);. Which call lets it exchange the values of int variables a and b?
Use swap(*a, *b), attempting to dereference the integers
Use swap(a, b), passing the integer values directly
Use swap(&a, &b), passing both variable addresses
Use swap(&a, b), passing one address and one value
4. Suppose int *p points to n, and void reset(int **slot) sets *slot to NULL. Which call allows reset to change p itself?
Call reset(p), passing the address stored in p
Call reset(*p), passing the integer reached through p
Call reset(&p), passing the address of the pointer variable
Call reset(&n), passing the address of the integer
5. Which statement correctly describes a null pointer?
It always points to memory containing the integer zero.
It points to no object; it may be compared with NULL but must not be dereferenced.
It points to the first element of an empty array.
It may be dereferenced safely, but its stored value cannot be changed.
6. For int a[6];, what is the result of &a[4] - &a[1]?
The address of a[3]
The size of three int objects in bytes
4
3
7. Given struct Node { int value; struct Node *next; }; and struct Node *cur;, how should cur be updated to point to the following node?
Assign the next member through the pointer: cur = cur->next;
Dereference before applying an invalid member form: cur = *cur.next;
Use direct structure-member syntax on the pointer: cur = cur.next;
Store the address of the pointer variable itself: cur = &cur;
8. In a C program that needs p to store the address of an int, which declaration is correct?
Use the pointer declaration int *p;
Declare an ordinary integer with int p;
Use the C++ reference syntax int &p;
Place the star after the name as int p*;
9. What does the declaration const int *p; allow?
Changing the pointed-to int through p, but not redirecting p
Neither redirecting p nor changing the pointed-to int by any means
Redirecting p while preventing modification of the pointed-to int through p
Only storing a null pointer value in p
10. Consider int n = 12; int *p = &n;. How can the value 12 be read through p?
Use p itself to obtain the stored address
Use &p to obtain the address of the pointer
Dereference the pointer with *p
Attempt to dereference the integer with *n
11. Consider int n = 25; void *vp = &n;. Which expression correctly reads n through vp?
Cast vp to int * and dereference it with *(int *)vp
Convert the pointer value directly to int with (int)vp
Dereference the void pointer directly with *vp
Take the address of the void-pointer variable with &vp
12. Given int a[] = {10, 20, 30, 40}; int *p = a;, what does *(p + 2) evaluate to?
20
30
The address of a[2]
A location two bytes beyond a[0]
13. After calling free(p) on a successfully allocated block, what best describes p if it has not been reassigned?
It automatically becomes NULL.
It is a dangling pointer whose stored address must not be dereferenced.
It remains valid until the current function returns.
It points to a new zero-initialized block.
14. What does second(values) return here? int second(const int *p) { return p[1]; } int values[] = {3, 7, 11};
3
The address of values[1]
11
7
15. What is the value of n after this code runs? int n = 4; int *p = &n; *p = 9;
4
The address stored in p
n is unchanged because only p changes
9
16. A local pointer is declared as int *p; and is not initialized. What should the program do before using *p?
Dereference p once so C can determine its target
Assign p a valid address before dereferencing it
Call free(p) to initialize it as a null pointer
Assume p points to an integer initialized to zero
Popular tests
Narcissistic Personality Inventory (NPI)
This self-report measure is used to assess narcissism as a personality trai…
Start Test
Yale-Brown Obsessive Compulsive Scale (Y-BOCS)
This measure is used to rapidly quantify the current severity of obsessive…
Start Test
CRAFFT Screening Test (CRAFFT 2.1)
This brief screening measure is designed to identify potential alcohol and…
Start Test
Patient Health Questionnaire-9 (PHQ-9)
This measure is commonly used to quickly screen for the presence and severi…
Start Test
Maslach Burnout Inventory (MBI)
This self-report measure is used to assess occupational burnout symptoms in…
Start Test
Adolescent Anxiety Questionnaire
This measure is designed to support a brief appraisal of anxiety symptoms a…
Start Test
Emotional Creativity Inventory (ECI)
This self-report measure assesses individual differences in the originality…
Start Test
Horne–Ostberg Morningness–Eveningness Questionnaire (MEQ)
Circadian preferences influence typical patterns of alertness and sleep tim…
Start Test
Ambivalent Sexism Inventory (ASI)
This measure is designed to assess attitudes toward women, including both o…
Start Test
Internalized Misogyny Scale (IMS)
This measure is designed to assess internalized negative beliefs and stereo…
Start Test
Perceived Stress Scale (PSS-10)
This self-report measure assesses the degree to which individuals appraise…
Start Test
Impulsive Behavior Scale (SUPPS-P)
Impulsivity is a multidimensional construct that is often assessed with bri…
Start Test
Clinical Institute Withdrawal Assessment for Alcohol, Revised (CIWA-Ar)
This rating scale is used to rapidly assess the severity of alcohol withdra…
Start Test
Positive and Negative Affect Schedule (PANAS)
This measure provides a brief self-report assessment of current or typical…
Start Test
Light Triad Scale (LTS)
This self-report measure assesses prosocial personality tendencies and orie…
Start Test
Suicidal Ideation Scale
In clinical settings, the Suicidal Ideation Scale is used to structure an i…
Start Test
Body Dysmorphic Disorder Scale (BDD-D)
This brief self-report measure is designed to screen for and quantify distr…
Start Test
Beck Anxiety Inventory (BAI)
This measure is a brief self-report inventory used to screen for anxiety sy…
Start Test
Differential Test of Perfectionism
This instrument is used to screen for perfectionism-related attitudes and t…
Start Test
Locus of Control Scale
This measure assesses generalized expectancies regarding the degree to whic…
Start Test
New Apathy Scale
This brief self-report measure is used to screen for apathy-related symptom…
Start Test
Perth Alexithymia Questionnaire (PAQ)
This measure assesses individual differences in alexithymia, including diff…
Start Test
Social Intelligence Scale
This brief self-report measure is designed to support rapid screening of in…
Start Test
Fear Test
This measure is designed to evaluate individual differences in fear-related…
Start Test
Neuroticism Level Scale
The measure is intended for brief screening of an individual’s propensity t…
Start Test
Aggressiveness Indicators Screening Questionnaire
This screening tool is designed to quickly identify behavioral indicators a…
Start Test