WorksheetsPointer and Memory Quiz - C/C++
Total questions: 10
Worksheet time: 5mins
Which of the following correctly declares a pointer to an integer?
int* ptr;
ptr int*;
int& ptr;
int ptr;
What is the purpose of the address-of operator (&)?
To de-reference a pointer
To obtain the value stored at a pointer's address
To declare a pointer variable
To get the memory address of a variable
If int x = 5; and int* ptr = &x;, what is the value of *ptr?
The memory address of x
5
The memory address of ptr
A garbage value
Which of the following statements about a null pointer is true?
It points to a memory location that is guaranteed to be valid and empty.
It can be dereferenced to get a value of 0.
It is a pointer that points to nothing, or to address 0.
It is a pointer that has been deallocated.
What is the result of sizeof(ptr) where int* ptr;?
The size of an integer (e.g., 4 bytes)
The size of the memory block pointed to by the pointer
The size of a memory address (e.g., 4 or 8 bytes)
A compilation error
Consider the following code snippet: int a = 10; int* ptr = &a; *ptr = 20; What is the value of a after this code executes?
10
20
The memory address of a
A garbage value
Which of the following is an example of pointer arithmetic?
ptr + 1
ptr / 2
ptr * 5
ptr - ptr2
What is the correct way to initialize a pointer to point to nothing?
int* ptr = NULL;
int* ptr = &0;
int* ptr = 0;
int* ptr = 'null';
If int arr[] = {1, 2, 3}; and int* ptr = arr;, what is the value of *(ptr + 1)?
1
2
3
A compile-time error
Which of the following is the dereference operator?
The ampersand (&)
The asterisk (*)
The dot (.)
The arrow (->)
