Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » C++ » Interview Questions on Pointers in C++

Interview Questions on Pointers in C++ : (8)


Question: 1

(A) Yes
(B) No

Compiler
Level: Beginner Category: pointers
[Posted by: | ]



Question: 2

(A) A pointer pointing to NULL
(B) Pointer pointing to memory location which has been freed
(C) Pointer which is pointing to new location
(D) None of these

Compiler
Level: Practitioner Category: pointers
[Posted by: | ]



Question: 3

(A) True
(B) False

Compiler
Level: Practitioner Category: pointers
[Posted by: | ]



Question: 4

(A) Program is terminated without printing anything on console
(B) Prints 'constructor' and then it is terminated
(C) constructor.destructor. but ptr is never freed
(D) constructor.destructor. And ptr is freed

Compiler
Level: Practitioner Category: pointers
[Posted by: | ]



Question: 5

(A) C++11's weak_ptrs are used with shared_ptrs.
(B) C++11's weak_ptrs can be used without weak_ptrs
(C) C++11's weak_ptrs are replacement of unique_ptr
(D) C++11's weak_ptrs are used for unique ownership

Compiler
Level: Practitioner Category: pointers
[Posted by: | ]



Question: 6

(A) We can only use these smart pointers to refer to objects allocated with new
(B) It is recommended that you do not use both 2 shared_ptr and raw pointer on the same object
(C) It can't be copied or assigned to another shared_ptr
(D) We can also reset a shared_ptr by assigning it the value nullptr

Compiler
Level: Practitioner Category: pointers
[Posted by: | ]



Question: 7

(A) This is valid code snippet with no error
(B) Error: Copy construction is not allowed at line 2
(C) Error: Assignment is not allowed at line 2
(D) Error: Runtime exception

Compiler
Level: Practitioner Category: pointers
[Posted by: | ]



Question: 8

(A) We can't transfer the ownership of unique pointers
(B) It is possible using copy constructor - unique_ptr<Thing> ptr2(ptr1);
(C) ptr2 = std::move(ptr1);
(D) ptr2 = ptr1

Compiler
Level: Expert Category: pointers
[Posted by: | ]