CBSE Class 12 Computer Science Chapter 7 Pointers NCERT Solutions

NCERT Solutions PDF Class 12 PDF

This chapter provides NCERT Solutions for Class 12 Computer Science, focusing on Chapter 7: Pointers. It covers essential concepts related to pointers, dynamic memory allocation, and their applications in C++. The solutions offer step-by-step explanations for various types of questions, including very short answer and short answer types. Students will find detailed guidance on defining functions to manipulate arrays based on specific conditions and implementing member functions for data structures like queues using dynamic memory. These solutions are designed to help students understand the practical implementation of pointers and related concepts, aiding in their exam preparation and strengthening their problem-solving skills in C++ programming.

Quick info

BoardCBSE
ClassClass 12
SubjectComputer Science
Session2026
LanguageEnglish
TypeNCERT Solutions
Chapter7. Pointers

Chapter summary

Chapter 7, 'Pointers,' in the CBSE Class 12 Computer Science curriculum focuses on the fundamental concepts of pointers in C++. The NCERT Solutions for this chapter provide clear explanations and solutions to problems involving pointer arithmetic, dynamic memory allocation (using new and delete), and the creation of dynamic data structures like linked lists and queues. The exercises cover defining functions that utilize pointers to modify array elements and implementing member functions for classes that manage dynamically allocated memory.

Learning outcomes

  • Understand the definition and application of functions that modify array elements based on conditions.
  • Learn to implement member functions for dynamic data structures like queues.
  • Grasp the concepts of dynamic memory allocation using 'new'.
  • Solve problems involving pointer manipulation in C++.
  • Write C++ code to manage dynamically allocated memory for data structures.

Topics covered

Paper topics

  • Pointers
  • Dynamic Memory Allocation
  • Array Manipulation
  • Functions with Arrays
  • C++ Classes
  • Queues
  • Linked Lists (implied)
  • Pointer Arithmetic

Important topics

  • Dynamic Memory Allocation using 'new'
  • Implementing Queue operations with pointers
  • Modifying array elements using functions and pointers
  • Pointer basics and their use in data structures

PDF preview

Read page by page below. PDF is streamed from the official NCERT website — no download button on this page.

Loading document …
Page of
Loading page …

Questions and Solutions

Question 1

Write the definition of a function FixPay (float Pay[], int N) in C++, which should modify each element of the array Pay having N elements, as per the following rules:

Existing Salary Value | Required Modification in Value

  • If less than 1,00,000: Add 25% in the existing value
  • If >= 1,00,000 and < 2,00,000: Add 20% in the existing value
  • If >= 2,00,000: Add 15% in the existing value
Solution:

The function `FixPay` takes a float array `Pay` and its size `N` as input. It iterates through each element of the array using a for loop. Inside the loop, it checks the value of the current element `Pay[i]` against the specified salary thresholds. Based on the condition met, it calculates the increment (25%, 20%, or 15% of the existing salary) and adds it to the element, thus modifying it in place.

void FixPay(float Pay[], int N) { for (int i = 0; i < N; i++) { if (Pay[i] < 100000) { Pay[i] += Pay[i] * 0.25; } else if (Pay[i] < 200000) { Pay[i] += Pay[i] * 0.20; } else { Pay[i] += Pay[i] * 0.15; } } }

Question 2

Write the definition of a member function INSERT() for a class QUEUE in C++, to remove a product from a dynamically allocated Queue of items considering the following code is already written as a part of the program.

struct ITEM { int INO; char INAME[20]; ITEM *Link; };

class QUEUE { ITEM *R, *F; Public: QUEUE() {R=NULL; F=NULL;} void INSERT(); void DELETE(); ~QUEUE(); };

Solution:

The `INSERT()` member function is defined for the `QUEUE` class. It first dynamically allocates memory for a new `ITEM` using the `new` operator. The user is prompted to enter the item number and item name, which are stored in the `INO` and `INAME` members of the new item, respectively. The `Link` pointer of the new item is set to `NULL` as it will be the last item. If the queue is empty (`R == NULL`), both the front (`F`) and rear (`R`) pointers are set to point to this new item. Otherwise, the `Link` of the current rear item is updated to point to the new item, and then the rear pointer `R` is updated to point to the newly added item.

void QUEUE::INSERT() { ITEM *newItem = new ITEM;

std::cout > newItem->INO;

std::cout INAME, 20);

newItem->Link = NULL;

if (R == NULL) // If the queue is empty { R = F = newItem; } else // If the queue is not empty { R->Link = newItem;

R = newItem; } }

Question 1

Write the output from the following C++ program code:

#include<iostream.h> #include<ctype.h> void strcon(char s[]) { for (int i=0, l=0; s[i]!='\0'; i++, l++); for(int j=0; j<1; j++) if(isupper(s[j])) // Missing code here

Solution:

The provided C++ code snippet defines a function `strcon` that takes a character array (string) `s` as input. The first loop iterates through the string to calculate its length, storing it in variable `l`. However, the variable `l` is not used subsequently. The second loop is intended to iterate, but its condition `j < 1` means it will only execute once for `j = 0`. Inside this loop, it checks if the first character of the string `s[0]` is an uppercase letter using `isupper()`. The code is incomplete as the action to be performed if `isupper(s[j])` is true is missing. Therefore, without the complete code, the exact output cannot be determined. Assuming the intention was to process the string based on its first character being uppercase, the code as presented does not produce any output or modify the string in a way that would be visible without further instructions.

Common mistakes

  • Incorrectly handling NULL pointers during dynamic memory allocation or deallocation.
  • Errors in pointer arithmetic, especially when dealing with arrays.
  • Forgetting to initialize pointers, leading to unpredictable behavior.
  • Memory leaks due to improper deallocation of dynamically allocated memory.

Revision tips

  • Review the syntax for declaring and initializing pointers.
  • Practice implementing dynamic memory allocation and deallocation for various data structures.
  • Work through the provided solutions to understand the logic behind pointer manipulation.
  • Pay close attention to edge cases, such as empty data structures or array boundaries.

Practice MCQs

Q1. What is the primary purpose of a pointer in C++?

Q2. Which operator is used to dynamically allocate memory in C++?

Q3. In the context of a dynamically allocated queue, what does `R->Link = newitem;` typically signify?

Q4. What is the role of `F` and `R` pointers in the `QUEUE` class?

Frequently asked questions

What are pointers in C++?

Pointers in C++ are special variables that store the memory address of other variables. They allow for direct memory manipulation and are crucial for dynamic memory allocation and complex data structures.

How does dynamic memory allocation work in C++?

Dynamic memory allocation in C++ uses the 'new' operator to allocate memory from the heap at runtime. This memory remains allocated until explicitly deallocated using the 'delete' operator or when the program terminates.

What is the significance of the `new` operator in the context of the QUEUE class?

The `new` operator is used within the `INSERT()` function of the `QUEUE` class to dynamically allocate memory for a new `ITEM` object. This allows the queue to grow as needed without a fixed size limit.

How can pointers be used to modify array elements?

Pointers can be used to access and modify array elements by storing the base address of the array. Pointer arithmetic allows traversal through the array elements, enabling functions to modify them directly.

What is the role of the `Link` member in the `ITEM` struct?

The `Link` member is a pointer to another `ITEM` structure. It is used to connect items in a dynamic data structure like a linked list or a queue, forming a chain of elements.

Content reviewed by the NCERT Help team. Editorial Team and update policy

NCERT Solutions PDF PDF on NCERT Help. URL unchanged for search indexing.