Search Header Logo

C++ Pointers and Memory Management Quiz

Authored by MAHANI BINTI ZAKARIA (POLIMAS)

Information Technology (IT)

University

Used 3+ times

C++ Pointers and Memory Management Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

5 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

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

int pointer;

int *pointer;

pointer int*;

int &pointer;

Answer explanation

To declare a pointer to an integer, we use after the data type: int pointer;. This means pointer can store the memory address of an integer.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What is the output of the following code?

num

10

ptr

&num

Answer explanation

To declare a pointer to an integer, we use after the data type: int pointer;. This means pointer can store the memory address of an integer.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which operator is used to get the address of a variable in C++?

*

&

@

#

Answer explanation

The ampersand (&) is used to get the memory address of a variable. For example, &x gives the address of variable x.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the relationship between a pointer and an array in C++?

Pointers cannot access array elements.

A pointer can point to only the last element of the array.

Array name is a constant pointer to the first element.

Arrays do not work with pointers.

Answer explanation

In C++, the name of the array acts like a pointer to the first element. That’s why you can use pointer arithmetic to access array elements.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the purpose of the new and delete operators in C++?

To perform multiplication and division.

To create and remove functions.

To allocate and free memory during runtime.

To declare variables.

Answer explanation

The new operator is used to allocate memory dynamically (during program running time), and delete is used to free that memory when it is no longer needed.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?