4 Pointers References And Memory Management

Object Oriented Programming · Unit 4

Pointers, References, and Memory Management

Exam-focused notes for Pointers, References, and Memory Management (Object Oriented Programming, BIT153): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.

What this unit covers

  • This pointer concept and uses
  • This pointer for name conflict resolution
  • Call by value and call by reference
  • Memory management operators: new and delete
  • Dynamic memory allocation
  • Static data members and static functions

This pointer concept and uses

20825 marks

What is the use of this pointer? Write a program to demonstrate it. [5]

The this pointer is an implicit pointer available inside every non-static member function of a class. It automatically points to the object that invoked the member function. Use Description ------------------ Resolve name conflict Distinguish between member...

Full solved answer →
05 marks

What are the uses of this pointer? Discuss its concept with suitable example. [5]

The this pointer is an implicit (hidden) pointer available inside every non-static member function of a class. It automatically holds the address of the object that invoked the member function. The compiler passes it as a hidden argument to every non-static...

Full solved answer →

This pointer for name conflict resolution

20805 marks

How 'this' pointer is used to resolve name conflict between local variable and member variable in C++? Explain with example. [5]

The this pointer is an implicit pointer available inside every non-static member function of a class. It automatically holds the address of the object that called the member function. Its type is ClassName. --- A name conflict arises when a local variable (...

Full solved answer →

Static data members and static functions

20805 marks

Illustrate the use of static variable with a simple program. [5]

A static variable is a variable that retains its value between function calls. It is initialized only once (at the first call) and exists for the entire lifetime of the program, even though its scope may be local to a function. --- Property Description ----...

Full solved answer →
20795 marks

What is the task of static data members and function? Illustrate with an example. [5]

A static data member is a class variable that is shared among all objects of that class. Unlike regular data members (which have separate copies for each object), only one copy of a static data member exists, regardless of how many objects are created. Key ...

Full solved answer →

Memory management operators

20785 marks

Explain Memory Management Operators of C++ with example. [5]

C++ provides two special memory management operators for dynamic memory allocation and deallocation at runtime: 1. new operator 2. delete operator These operators allow programs to request memory from the heap (free store) during program execution, rather t...

Full solved answer →

Call by value and call by reference

20785 marks

Explain Call by Value and Call by Reference with appropriate example. [5]

In Call by Value, a copy of the actual argument is passed to the formal parameter of the function. Any changes made to the formal parameter inside the function do not affect the original (actual) argument. - The actual and formal parameters occupy separate ...

Full solved answer →