CBSE Class 12 Computer Science C++ Chapter 7: Pointers NCERT Solutions

NCERT Solutions PDF Class 12 PDF

This chapter provides NCERT Solutions for Class 12 Computer Science (C++) focusing on Pointers. It covers essential concepts related to memory addresses, dynamic memory allocation, and their applications. The solutions explain how to define functions that manipulate array elements based on specific conditions, such as adjusting salaries. It also details the implementation of a member function to insert elements into a dynamically allocated queue, demonstrating the management of pointers for linked structures. Furthermore, the chapter includes exercises on string manipulation and output prediction, reinforcing understanding of C++ programming constructs. These solutions are designed to help students grasp the intricacies of pointers and dynamic memory management, crucial for advanced programming tasks and exam preparation.

Quick info

BoardCBSE
ClassClass 12
SubjectComputer Science (C++)
Session2026
LanguageEnglish
TypeNCERT Solutions
ChapterChapter 7

Chapter summary

Chapter 7, 'Pointers,' for CBSE Class 12 Computer Science (C++) provides solutions to exercises focusing on pointer manipulation, dynamic memory allocation, and array processing. It includes problems on function definitions for array element modification, implementing queue operations using dynamic memory, and predicting program output based on string and character handling. The solutions aim to solidify students' understanding of how pointers manage memory and data structures.

Learning outcomes

  • Understand the definition and application of functions for array manipulation.
  • Learn to implement dynamic memory allocation for data structures like queues.
  • Analyze and predict the output of C++ programs involving string and character functions.
  • Grasp the concept of pointers in managing memory and data.

Topics covered

Paper topics

  • Pointers
  • Dynamic Memory Allocation
  • Arrays
  • Functions
  • Queues
  • Linked Lists
  • String Manipulation
  • Character Handling Functions

Important topics

  • Pointer Declaration and Usage
  • Dynamic Memory Allocation (`new`, `delete`)
  • Implementing Data Structures with Pointers (e.g., Queues)
  • Array Manipulation using Pointers
  • String Processing Functions

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

Very Short Answer Type Questions - 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 conditions.

If `Pay[i]` is less than 1,00,000, 25% of its current value is added to it. If `Pay[i]` is greater than or equal to 1,00,000 but less than 2,00,000, 20% is added. Otherwise (if `Pay[i]` is 2,00,000 or more), 15% is added. This ensures each element is modified according to the given rules.

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; } } }

Very Short Answer Type Questions - 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 for the `QUEUE` class is defined to add a new item to the rear of a dynamically allocated queue. First, a new `ITEM` node is created using `new`. The user is prompted to enter the item number (`INO`) and item name (`INAME`). The `Link` pointer of the new item is set to `NULL` as it will be the last item.

If the queue is initially empty (`R == NULL`), both the front (`F`) and rear (`R`) pointers are set to point to the new item. Otherwise, if the queue is not empty, the `Link` pointer of the current rear item (`R`) is updated to point to the new item, and then the rear pointer (`R`) itself is updated to point to this newly added item, effectively placing it at the end of the queue.

void QUEUE::INSERT() {

ITEM* newItem = new ITEM;

std::cout << "Enter item number: ";

std::cin >> newItem->INO;

std::cout << "Enter item name: ";

// Using std::cin.ignore() and std::cin.getline() for safer string input

std::cin.ignore();

std::cin.getline(newItem->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; } }

Short Answer Type Questions-I - 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])) // ... (rest of the code is missing or truncated in source)

Solution:

The provided C++ code snippet is incomplete, specifically the `strcon` function and the main part of the program are truncated. However, we can analyze the visible parts.

The first loop in `strcon` iterates through the character array `s` until it finds the null terminator (`'\0'`). It uses two integer variables, `i` and `l`, both incrementing in each iteration. The variable `i` acts as the index for traversing the string, and `l` also increments, effectively counting the characters in the string (similar to `strlen`).

The second loop `for(int j=0; j<1; j++)` is intended to run only once (for `j=0`). Inside this loop, `isupper(s[j])` checks if the character at index `j` (which is `s[0]`) is an uppercase letter. If it is, some action is supposed to follow, but the code is cut off.

Without the complete code, it is impossible to determine the exact output. The program likely intends to perform some operation based on the first character of the string `s` being uppercase, possibly related to string conversion or manipulation, but the final logic is missing.

Common mistakes

  • Incorrectly handling pointer assignments and dereferencing.
  • Errors in dynamic memory allocation and deallocation (memory leaks).
  • Off-by-one errors in loop conditions when processing arrays or strings.
  • Misunderstanding the behavior of character and string manipulation functions.

Revision tips

  • Review the syntax for declaring and using pointers thoroughly.
  • Practice implementing dynamic memory allocation for linked lists and queues.
  • Trace the execution of C++ code snippets involving arrays and strings to predict output.
  • Focus on understanding the conditions and modifications in array element adjustment problems.

Practice MCQs

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

Q2. In the FixPay function, what is the percentage increase for salaries less than 1,00,000?

Q3. What does the `new` keyword do in C++?

Q4. In a dynamically allocated queue, what does `R` typically represent?

Q5. The `isupper()` function checks if a character is:

Frequently asked questions

What is the main focus of Chapter 7 NCERT Solutions for Class 12 Computer Science?

Chapter 7 focuses on Pointers in C++, covering concepts like dynamic memory allocation, array manipulation using pointers, and implementing data structures such as queues.

How do these solutions help in understanding pointers?

The solutions provide rewritten, step-by-step explanations for various problems, clarifying how pointers are used to manage memory and data structures effectively.

Are the questions in the solutions exactly the same as in the NCERT textbook?

Yes, the questions are preserved with their original numbering and problem statements. The wording has been expanded for clarity where needed.

What kind of programming concepts are covered in the exercises?

The exercises cover function definitions for array modifications, implementing queue insertion using dynamic memory, and predicting program output involving string functions.

Can these solutions help with exam preparation?

Yes, by providing clear explanations and rewritten solutions, these resources aid in understanding complex topics like pointers and dynamic memory, which are important for exams.

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

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