Unit 2: Pointers, Reference Variables, Arrays and String Concepts - Subjective Questions

CSE202 — Object Oriented Programming • Practice Questions with Detailed Answers

20 questions

1

Define a void pointer in C++. Explain its characteristics, limitations, and type casting with a suitable example.

2

Explain pointer arithmetic in C++. Describe the operations permitted on pointers and illustrate how the data type affects address movement.

3

What is a pointer to pointer? Explain its declaration, initialization, and dereferencing. Mention two practical applications.

4

Define dangling pointer, wild pointer, and null pointer. Compare their causes and explain how each should be handled safely.

5

Explain null pointer assignment in modern C++. Compare nullptr, NULL, and 0, and demonstrate a safe null check.

6

Describe the problems involved when a class contains a pointer data member. Explain deep copying using the Rule of Three with a suitable class design.

7

What is a pointer to an object? Explain how object members are accessed through object pointers and how dynamic objects are created and destroyed.

8

Explain the purpose and behavior of the this pointer in C++. Discuss its use in resolving name conflicts, returning the current object, and preventing self-assignment.

9

Define an array of objects. Explain how constructors are invoked for its elements and demonstrate static and dynamic arrays of objects.

10

Describe different ways of defining, initializing, and assigning std::string objects in C++. How do they differ from C-style strings?

11

Explain any five commonly used std::string member functions with syntax and examples.

12

What are string class modifiers? Explain the operation of append, insert, erase, replace, push_back, pop_back, and clear.

13

Distinguish between pointer variables and reference variables in C++. Include declaration, initialization, reassignment, nullability, arithmetic, and syntax of access.

14

Explain the declaration, initialization, and processing of a two-dimensional array inside main(). Show how its elements are stored and accessed.

15

Describe how a multidimensional array can be used as a data member of a class. Write a class that accepts and displays a matrix.

16

Explain how a built-in two-dimensional array is passed to a function. Why must all dimensions except the first normally be specified?

17

What is a pointer to data member in C++? Explain its declaration, initialization, and use with both an object and an object pointer.

18

Compare a pointer to data member, an ordinary pointer, and a pointer to an object. Provide an example showing their different access operators.

19

Analyze the following pointer operations and explain which statements are valid or unsafe: subtracting array pointers, comparing pointers, dereferencing the one-past-end pointer, and performing arithmetic on unrelated pointers.

20

Design a C++ class that combines an array of objects, object pointers, the this pointer, and std::string operations. Explain how these concepts interact in the design.