wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Pointer and Memory Quiz - C/C++

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which of the following correctly declares a pointer to an integer?

a)

int* ptr;

b)

ptr int*;

c)

int& ptr;

d)

int ptr;

2.

What is the purpose of the address-of operator (&)?

a)

To de-reference a pointer

b)

To obtain the value stored at a pointer's address

c)

To declare a pointer variable

d)

To get the memory address of a variable

3.

If int x = 5; and int* ptr = &x;, what is the value of *ptr?

a)

The memory address of x

b)

5

c)

The memory address of ptr

d)

A garbage value

4.

Which of the following statements about a null pointer is true?

a)

It points to a memory location that is guaranteed to be valid and empty.

b)

It can be dereferenced to get a value of 0.

c)

It is a pointer that points to nothing, or to address 0.

d)

It is a pointer that has been deallocated.

5.

What is the result of sizeof(ptr) where int* ptr;?

a)

The size of an integer (e.g., 4 bytes)

b)

The size of the memory block pointed to by the pointer

c)

The size of a memory address (e.g., 4 or 8 bytes)

d)

A compilation error

6.

Consider the following code snippet: int a = 10; int* ptr = &a; *ptr = 20; What is the value of a after this code executes?

a)

10

b)

20

c)

The memory address of a

d)

A garbage value

7.

Which of the following is an example of pointer arithmetic?

a)

ptr + 1

b)

ptr / 2

c)

ptr * 5

d)

ptr - ptr2

8.

What is the correct way to initialize a pointer to point to nothing?

a)

int* ptr = NULL;

b)

int* ptr = &0;

c)

int* ptr = 0;

d)

int* ptr = 'null';

9.

If int arr[] = {1, 2, 3}; and int* ptr = arr;, what is the value of *(ptr + 1)?

a)

1

b)

2

c)

3

d)

A compile-time error

10.

Which of the following is the dereference operator?

a)

The ampersand (&)

b)

The asterisk (*)

c)

The dot (.)

d)

The arrow (->)