LearnFrenzy
Sign in Take a free test

Pointers and Dynamic Memory · Exercise 1 of 4

Pointers and Dynamic Memory Pointers MCQ

  • 20 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on C++ pointers: addresses, dereferencing, nullptr, pointer arithmetic, const pointers, new and delete, leaks, dangling pointers and RAII. Pick an option to check your answer instantly.

Question 11 Easy

How must int* a = new int[10]; be released?

A delete a;
B delete[] a;
C free(a);
D It is freed automatically
Question page & discussion
Question 12 Easy

What does int* p = nullptr; delete p; do?

A Crashes
B Nothing – deleting a null pointer is a no-op
C Frees address 0
D Undefined behaviour
Question page & discussion
Question 13 Easy

Which code leaks memory?

A int x = 5;
B int* p = new int(1); p = new int(2); delete p;
C int* p = new int(1); delete p;
D std::vector<int> v(100);
Question page & discussion
Question 14 Easy

What is a dangling pointer?

A A null pointer
B A pointer to memory that has been freed or to an object whose lifetime has ended
C A pointer to a pointer
D An uninitialized pointer
Question page & discussion
Question 15 Medium

Which is true about void* v?

A *v gives the value as an int
B It can hold any object address, but must be cast to a typed pointer before dereferencing
C It can only point to functions
D It is the same as nullptr
Question page & discussion
Question 16 Easy

On a typical 64-bit system, what are sizeof(char*) and sizeof(double*)?

A 1 and 8
B 8 and 8
C 4 and 8
D 8 and 16
Question page & discussion
Question 17 Medium

Which statement about stack and heap memory is correct?

A Heap memory is freed automatically at the end of a block
B Local variables live on the stack and vanish at the end of their scope; memory from new lives on the heap until deleted
C The stack is unlimited
D new allocates on the stack
Question page & discussion
Question 18 Medium

What is the idea behind RAII?

A Random Access In Iterators
B An object acquires a resource in its constructor and releases it in its destructor, so cleanup happens automatically
C Always initialize integers
D Pointers must be checked at run time
Question page & discussion
Question 19 Medium

Why would a function take an int** parameter?

A To read an int faster
B To change which address the caller's int* holds (e.g. to allocate memory for it)
C To receive a 2D array of any size
D int** is the same as int*
Question page & discussion
Question 20 Medium

What does plain new do when the requested memory is not available?

A Returns nullptr
B Throws std::bad_alloc
C Returns garbage
D Allocates on the stack instead
Question page & discussion
Up next · Exercise 2Predict the Output20 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links