Kerala Plus Two Computer Science Previous Questions Chapter 1 Structures and Pointers

Official Kerala Board Solutions for Class 12 Computer Science: Chapter 01 Structures and Pointers

Review structured textbook solutions for Class 12 Computer Science Chapter 01 Structures and Pointers. Built according to Kerala Board guidelines for the 2026-27 academic year, these downloadable answers support daily revision and problem-solving accuracy.

Chapter-wise Solutions for Computer Science: Chapter 01 Structures and Pointers

Access the complete solution PDF for Class 12 Computer Science below. Regular practice with these targeted textbook answers builds familiarity with standard question patterns and helps secure higher marks in final school evaluations.

Previous Questions and Answers

Question 1: Represent a structure named student with types and give the advantages of using structure. (March 2016)

Answer:

struct student
{
 int regno;
 char name[25];
 struct
 {
  short dd;
  short mm;
  short yy;
 } dob;
 char sex;
};

A structure is a group of logically related data items of different types that are referred to by a single name.
Here the details of a student (register number, name, date of birth and sex) are kept together under the name student, and the date of birth is itself a nested structure.
Advantage: related data of different types can be handled as a single unit, which makes the program easier to read and manage.

Exam Tips:

a) Write the structure with the keyword struct, a tag name, the members inside braces and a semicolon at the end.
b) The question carries 3 marks, so give the structure definition and at least one clear advantage.

 

Question 2: A structure within a structure is termed as ______. (March 2016)

Answer:

Nested structure

Exam Tips:

a) A structure that has another structure as one of its members is called a nested structure.

 

Question 3: Orphaned memory blocks are undesirable. How can they be avoided? (March 2016)
OR
Discuss the problems created by memory leaks.

Answer:

Orphaned memory blocks are avoided by using the delete operator properly to release memory that was allocated with the new operator.
OR
Problems caused by memory leaks:
1) It creates orphaned memory blocks.
2) Memory is wasted.
3) The system may run out of memory.
4) Because of this, the system may sometimes hang.

Exam Tips:

a) Answer the version of the question you choose and mark it clearly (for example, write "OR" between the two answers only if you attempt both).
b) Link the cause (not using delete) to the effect (memory leak) in your answer.

 

Question 4: Explain the use of the for loop with an appropriate example. (March 2016)

Answer:

The for loop is an entry-controlled loop that is used to execute a statement or a block of statements repeatedly for a fixed number of times.
Syntax:

for(initialization; test expression; update expression)
{
 body of the loop;
}

The initialization is executed once. Then the test expression is checked, and as long as it is true the body is executed and the update expression is applied.
Example: a program to print the numbers from 1 to 5.

#include<iostream>
using namespace std;
int main()
{
 for(int i=1; i<=5; i++)
  cout<<i<<" ";
 return 0;
}

Output: 1 2 3 4 5

Exam Tips:

a) Give the general form (syntax) of the loop first and then a short example.
b) Name the three parts: initialization, test expression and update expression.

 

Question 5: a) How will you free the allocated memory? (May 2016)
b) Define a structure called time to group the hours, minutes and seconds. Also write a statement that declares two variables current_time and next_time which are of type struct time.

Answer:

a) The delete operator is used to free the memory that was allocated with the new operator.
b)

struct time
{
 int hours;
 int minutes;
 int seconds;
};
time current_time, next_time;

Exam Tips:

a) In part (a) also mention that delete is used with the pointer that holds the address returned by new.
b) In part (b) use the variable names exactly as given in the question.

 

Question 6: A program is implemented to find the area of a circle and the area of a rectangle with two functions having the same name but with different signatures. (May 2016)
a) Name the concept.
b) Explain this concept by writing the above program.

Answer:

a) Polymorphism (function overloading)
b)

#include<iostream>
#include<cmath>
using namespace std;
float area(float r)
{
 return (3.14*pow(r,2));
}
int area(int l, int b)
{
 return (l*b);
}
int main()
{
 float r, Ac;
 int l, b, Ar;
 cout<<"Enter the radius of the circle";
 cin>>r;
 Ac=area(r);
 cout<<"Enter the length and breadth";
 cin>>l>>b;
 Ar=area(l,b);
 cout<<"Area of circle is "<<Ac;
 cout<<"\nArea of rectangle is "<<Ar;
 return 0;
}

Here both functions have the same name area, but they differ in the number and type of parameters. The compiler decides which function to call by looking at the arguments, so the functions are distinguished by their signatures.

Exam Tips:

a) Write the concept as "Polymorphism (function overloading)" to be safe.
b) Remember that functions cannot be overloaded on the return type alone; the parameter list must differ.

 

Question 7: a) Write a C++ program to store and print information (name, roll and marks) of a student using structure. (May 2016)
OR
b) Write a program in C++ to input the total marks obtained by a group of students in a class and display them in descending order using pointer.

Answer:

a)

#include<iostream>
using namespace std;
int main()
{
 struct student
 {
  char name[40];
  int roll;
  int marks[6];
 } S1;
 cout<<"Enter name: ";
 cin>>S1.name;
 cout<<"Enter roll no: ";
 cin>>S1.roll;
 cout<<"Enter 6 marks: ";
 for(int i=0; i<6; i++)
  cin>>S1.marks[i];
 cout<<"The details are given below";
 cout<<"\nName: "<<S1.name;
 cout<<"\nRoll No: "<<S1.roll;
 for(int i=0; i<6; i++)
  cout<<"\nMark "<<i+1<<": "<<S1.marks[i];
 return 0;
}

OR
b)

#include<iostream>
using namespace std;
int main()
{
 int mark[50], i, j, *ptr, n, temp;
 ptr=mark;
 cout<<"Enter how many students: ";
 cin>>n;
 for(i=0; i<n; i++)
 {
  cout<<"Enter mark "<<i+1<<": ";
  cin>>*(ptr++);
 }
 for(i=0; i<n-1; i++)
  for(j=i+1; j<n; j++)
   if(mark[i]<mark[j])
   {
    temp=mark[i];
    mark[i]=mark[j];
    mark[j]=temp;
   }
 ptr=mark;
 cout<<"The marks in descending order";
 for(i=0; i<n; i++)
  cout<<*(ptr++)<<endl;
 return 0;
}

Exam Tips:

a) Attempt only one of the two options; part (b) needs pointer notation such as *(ptr++).
b) For descending order, swap when the earlier element is smaller than the later one.
c) Include the header file and using namespace std in every program.

 

Question 8: Compare the aspects of arrays and structures. (March 2017)

Answer:

Array: An array is a collection of elements of the same data type that share a common name. The elements are distinguished by the index (subscript). The first element has index 0, the second has index 1, and so on.
To store 100 numbers, the declaration is int n[100]; The index of the first element is 0 and the index of the last element is 99.
Structure: A structure is a group of logically related data items of different types that are referred to by a single name.
Example: the details of a student, which may contain data of different types.

struct student
{
 int adm_no;
 char name[40];
 float weight;
};

OR

StructureArray
1. It is a user-defined data typeIt is a derived data type built from a predefined data type
2. It is a collection of different types of logically related data under one nameIt is a collection of data elements of the same data type having a common name
3. Elements are referenced using the dot operator (.)Elements are referenced using the subscript (position value)
4. When an element of a structure is another structure, it is called a nested structure and complex structures are formedWhen an element of an array is another array, multidimensional arrays are formed
5. A structure can contain an array as its elementAn array of structures can be formed

Exam Tips:

a) A table with at least three points of difference is the quickest way to score full marks.
b) Always include a small example for each of the two.

 

Question 9: Run time allocation of memory is triggered by the operator ______. (March 2017)

Answer:

new

Exam Tips:

a) new allocates memory at run time (dynamic allocation) and delete releases it.

 

Question 10: Represent the names of 12 months as an array of strings. (March 2017)
OR
A structure can contain another structure. Discuss.

Answer:

char month[12][10]={"Jan","Feb","Mar","Apr","May","Jun","July","Aug","Sep","Oct","Nov","Dec"};
OR
Yes, it is possible. A structure inside another structure is called a nested structure.
Example:

struct date
{
 short day, month, year;
};
struct student
{
 int reg_no;
 char name[40];
 date dob;
};

Exam Tips:

a) Remember that a string array is a two-dimensional character array: the first index gives the number of strings and the second gives the maximum length.
b) For the nested structure, show the inner structure defined before it is used.

 

Practice Questions

Question 11: Define a structure to represent the details of telephone subscribers which include the name of the subscriber and telephone number. Write a menu driven program to store the details of some subscribers with options for searching the name for a given number, and the number for a given name.

Answer:

#include<iostream>
#include<cstring>
using namespace std;
struct directory
{
 char name[20];
 int ph_no;
};
int main()
{
 directory d[20];
 int ch, n=0, i;
 do
 {
  cout<<"\nEnter 1 for Add name and phone number";
  cout<<"\n2 for search by name \n3 for search by number";
  cout<<"\n4 for exit:";
  cin>>ch;
  switch(ch)
  {
   case 1:
    ++n;
    cout<<"Enter name :";
    cin>>d[n].name;
    cout<<"Enter phone number(7 Digits):";
    cin>>d[n].ph_no;
    break;
   case 2:
    char name[20];
    cout<<"Enter name to be searched:";
    cin>>name;
    for(i=1; i<=n; i++)
    {
     if(strcmp(d[i].name,name)==0)
     {
      cout<<"\nName found the corresponding number is "<<d[i].ph_no;
      break;
     }
    }
    if(i>n)
     cout<<"\nNo Such name. Please try again";
    break;
   case 3:
    int pno;
    cout<<"Enter phone number to be searched:";
    cin>>pno;
    for(i=1; i<=n; i++)
    {
     if(d[i].ph_no==pno)
     {
      cout<<"\nNumber found the corresponding name is "<<d[i].name;
      break;
     }
    }
    if(i>n)
     cout<<"\nNo Such Number. Please try again";
    break;
   default:
    cout<<"thank you";
  }
 } while(ch==1 || ch==2 || ch==3);
 return 0;
}

Sample output: after adding the names Andrea (2828159) and Alvis (2345619), searching for the name Alvis gives the number 2345619, searching for the number 2828159 gives the name Andrea, and searching for the name Jose gives "No Such name. Please try again". Entering 4 ends the program with "thank you".

Exam Tips:

a) Define the structure first, then declare an array of that structure in main().
b) Use strcmp() (header cstring) to compare names; the == operator cannot compare strings.
c) After the search loop, test whether the loop ended without a match (i>n) to print the "not found" message.

 

Question 12: Define a structure to represent the details of customers in a bank. The details include account number, name, date of opening the account and balance amount. Write a menu driven program to input the details of a customer and provide options to deposit, withdraw and view the details. During deposit and withdrawal, proper update is to be made in the balance amount. A minimum balance of Rs. 1000/- is a must in the account.

Answer:

#include<iostream>
using namespace std;
struct date
{
 int day, month, year;
};
struct customer
{
 int accno;
 char name[20];
 date dop;
 float balance;
};
int main()
{
 customer c[20];
 int ch, n=0, i;
 int accno;
 float amt;
 do
 {
  cout<<"\nEnter 1 for Add New Customer";
  cout<<"\n2 for Deposit\n3 for Withdraw\n4 for View details";
  cout<<"\n5 for exit:";
  cin>>ch;
  switch(ch)
  {
   case 1:
    ++n;
    cout<<"Enter Acc No :";
    cin>>c[n].accno;
    cout<<"Enter Name:";
    cin>>c[n].name;
    cout<<"Enter Date of Opening the Account(Day,Month,Year):";
    cin>>c[n].dop.day>>c[n].dop.month>>c[n].dop.year;
    cout<<"Enter the Amount(not less than 1000):";
    cin>>c[n].balance;
    break;
   case 2:
    cout<<"Enter Acc No:";
    cin>>accno;
    for(i=1; i<=n; i++)
    {
     if(c[i].accno==accno)
     {
      cout<<"\nEnter the amount to be deposited:";
      cin>>amt;
      c[i].balance+=amt;
      cout<<"\nThe amount deposited and the available balance is "<<c[i].balance;
      break;
     }
    }
    if(i>n)
     cout<<"\nNo such Acc No. Try again";
    break;
   case 3:
    cout<<"Enter Acc No:";
    cin>>accno;
    for(i=1; i<=n; i++)
    {
     if(c[i].accno==accno)
     {
      cout<<"Enter the amount to be withdrawn:";
      cin>>amt;
      if(c[i].balance-amt<1000)
       cout<<"Not enough Money. Try again";
      else
      {
       c[i].balance-=amt;
       cout<<"The available balance is "<<c[i].balance;
      }
      break;
     }
    }
    if(i>n)
     cout<<"No such Acc No. Try again";
    break;
   case 4:
    cout<<"Enter Acc No:";
    cin>>accno;
    for(i=1; i<=n; i++)
    {
     if(c[i].accno==accno)
     {
      cout<<"\nAcc No: "<<c[i].accno;
      cout<<"\nName: "<<c[i].name;
      cout<<"\nDate of opening: "<<c[i].dop.day<<"/"<<c[i].dop.month<<"/"<<c[i].dop.year;
      cout<<"\nBalance: "<<c[i].balance;
      break;
     }
    }
    if(i>n)
     cout<<"No such Acc No. Try again";
    break;
   default:
    cout<<"thank you";
  }
 } while(ch>=1 && ch<=4);
 return 0;
}

Exam Tips:

a) Use a nested structure (date inside customer) for the date of opening.
b) Before a withdrawal, check that balance - amount is at least 1000 so that the minimum balance rule is not broken.
c) Every option should search for the account number first and print a message if it is not found.

 

Question 13: Write a program to input the TE scores obtained by a group of students in Computer Science and display them in the descending order using pointers.

Answer:

#include<iostream>
using namespace std;
int main()
{
 int i, j, temp, *ptr, n, mark[100];
 ptr=mark;
 cout<<"Enter the number of students:";
 cin>>n;
 for(i=0; i<n; i++)
 {
  cout<<"Enter TE Score "<<i+1<<":";
  cin>>*(ptr++);
 }
 ptr=mark;
 cout<<"The "<<n<<" marks are given below\n";
 for(i=0; i<n; i++)
  cout<<*(ptr++)<<endl;
 ptr=mark;
 for(i=0; i<n-1; i++)
  for(j=i+1; j<n; j++)
   if(*(ptr+i)<*(ptr+j))
   {
    temp=*(ptr+i);
    *(ptr+i)=*(ptr+j);
    *(ptr+j)=temp;
   }
 ptr=mark;
 cout<<"The marks in descending order are given below\n";
 for(i=0; i<n; i++)
  cout<<*(ptr++)<<endl;
 return 0;
}

Exam Tips:

a) Reset the pointer with ptr=mark after every loop that moves it.
b) Use *(ptr+i) to access elements without changing the pointer.
c) Swap when the earlier element is smaller than the later one to get descending order.

 

Question 14: Write a program to input a string and check whether it is a palindrome or not using a character pointer.

Answer:

#include<iostream>
using namespace std;
int main()
{
 char s[50], *str=s;
 int len, i, j, flag=0;
 cout<<"Enter a string";
 cin>>s;
 for(i=0; *(str+i)!='\0'; i++);
 len=i;
 for(i=0, j=len-1; i<len/2; i++, j--)
 {
  if(*(str+i)!=*(str+j))
  {
   flag=1;
   break;
  }
 }
 if(flag==1)
  cout<<"It is not palindrome";
 else
  cout<<"It is palindrome";
 return 0;
}

Exam Tips:

a) First find the length of the string by moving the pointer until the null character.
b) Compare the first character with the last, the second with the second last, and so on up to half the length.
c) A flag variable makes the final decision simple.

 

Question 15: Write a program to input the names of students in a class using pointers and create a roll list in which the names are listed in alphabetical order with roll number starting from 1.

Answer:

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
 char *names[25], *temp;
 int i, j, n;
 cout<<"Enter the number of students:";
 cin>>n;
 for(i=0; i<n; i++)
 {
  names[i]=new char[20];
  cout<<"Enter the name of student "<<i+1<<":";
  cin>>names[i];
 }
 cout<<"The names you entered are given below\n";
 for(i=0; i<n; i++)
  cout<<names[i]<<endl;
 for(i=0; i<n-1; i++)
  for(j=i+1; j<n; j++)
   if(strcmp(names[i],names[j])>0)
   {
    temp=names[i];
    names[i]=names[j];
    names[j]=temp;
   }
 cout<<"Roll No\tName\n";
 for(i=0; i<n; i++)
  cout<<i+1<<"\t"<<names[i]<<endl;
 for(i=0; i<n; i++)
  delete[] names[i];
 return 0;
}

Exam Tips:

a) Allocate memory for every name with new before reading it, and release it with delete[] at the end.
b) Swap the pointers instead of copying the strings; it is faster and simpler.
c) strcmp(a,b)>0 means a comes after b in alphabetical order.

 

Question 16: Define a structure student with the details register number, name and CE marks of six subjects. Using a structure pointer, input the details of a student and display register number, name and total CE score.

Answer:

#include<iostream>
#include<iomanip>
using namespace std;
struct student
{
 int regno;
 char name[20];
 int mark[6];
 int total;
};
int main()
{
 int n, i, j;
 cout<<"Enter how many students data :";
 cin>>n;
 student *s=new student[n];
 for(i=0; i<n; i++)
 {
  cout<<"Enter Reg No of Student"<<i+1<<":";
  cin>>(s+i)->regno;
  cout<<"Enter name of student"<<i+1<<":";
  cin>>(s+i)->name;
  (s+i)->total=0;
  for(j=0; j<6; j++)
  {
   cout<<"Enter CE mark"<<j+1<<" of Student"<<i+1<<":";
   cin>>(s+i)->mark[j];
   (s+i)->total+=(s+i)->mark[j];
  }
 }
 cout<<"Reg No\tName\t\tTotal CE Score\n";
 for(i=0; i<n; i++)
  cout<<setw(4)<<(s+i)->regno<<setw(8)<<(s+i)->name<<setw(20)<<(s+i)->total<<endl;
 delete[] s;
 return 0;
}

Sample output: for the student Raju (Reg No 1020) with CE marks 20, 20, 19, 28, 20, 19 the total shown is 126, and for Jose (Reg No 1021) with marks 20, 20, 20, 19, 19, 19 the total is 117.

Exam Tips:

a) Use the arrow operator (->) with a structure pointer, for example (s+i)->regno.
b) Set the total to 0 before adding the six marks.
c) Include iomanip when using setw() to align the output.

 

Assess Question and Answers

Question 17: Compare array and structure in C++.

Answer:

StructureArray
1. It is a user-defined data typeIt is a derived data type built from a predefined data type
2. It is a collection of different types of logically related data under one nameIt is a collection of data elements of the same data type having a common name
3. Elements are referenced using the dot operator (.)Elements are referenced using the subscript (position value)
4. When an element of a structure is another structure, it is called a nested structure and complex structures are formedWhen an element of an array is another array, multidimensional arrays are formed
5. A structure can contain an array as its elementAn array of structures can be formed

Exam Tips:

a) Present the answer as a table; the differences are then clear to the examiner.
b) Give at least as many points as the marks for the question.

 

Question 18: Identify the errors in the following structure definition and write the reason for each:
struct
{
 int roll, age;
 float fee= 1000:
};

Answer:

Errors:
1) The structure has no name (tag), so variables of this type cannot be declared later.
2) A member cannot be initialised inside a structure definition (fee=1000 is not allowed).
3) The statement ends with a colon instead of a semicolon.
The correct structure is as follows:

struct student
{
 short roll, age;
 float fee;
};

Exam Tips:

a) Check each line of the structure for the tag, the member declarations and the semicolons.
b) Initial values are given to structure variables when they are declared, not inside the definition.

 

Question 19: Read the following structure definition and answer the following questions:
struct Book
{
 int book_no;
 char bk_name[20];
 struct
 {
  short dd;
  short mm;
  short yy;
 } dt_of_purchase;
 float price;
};
a) Write a C++ statement to declare a variable to refer to the details of a book. What is the memory requirement of this variable? Justify your answer.
b) Write a C++ statement to initialize this variable with the details of your Computer Science text book.
c) Write C++ statement(s) to display the details of the book.
d) The missing of structure tag in the inner structure does not cause any error. State whether this is true or false. Give reason.

Answer:

a) Book b;
The memory requirements are as follows:

VariableMemory size (bytes)
book_no4
bk_name20
dt_of_purchase2+2+2 = 6
price4

A total of 34 bytes is allocated to the variable b (4 + 20 + 6 + 4), because the memory of a structure variable is the sum of the memory of its members.

b) Book b={101,"Computer Science",{22,9,2015},127};

c)

cout<<"Book No: "<<b.book_no<<endl;
cout<<"Book Name: "<<b.bk_name<<endl;
cout<<"Date of Purchase: "<<b.dt_of_purchase.dd<<"/"<<b.dt_of_purchase.mm<<"/"<<b.dt_of_purchase.yy<<endl;
cout<<"Price: "<<b.price;

d) True. There is no need to mention the structure tag of the inner structure because its variable (dt_of_purchase) is declared inside the structure itself, along with the definition.

Exam Tips:

a) In part (a) show the calculation of memory by adding the sizes of all members (int 4, short 2, float 4 and 20 for the character array).
b) Refer to the inner members with the chain of dot operators, for example b.dt_of_purchase.dd.
c) In part (d) give the reason: the inner structure is used only once, to declare dt_of_purchase.

 

Question 20: "Structure is a user-defined data type". Justify this statement with the help of an example.

Answer:

Yes, it is true. A user can define a structure according to his or her own needs by combining data items of different types, and then use its name as a new data type to declare variables.
Example: a structure to store a date and a variable of that type.

#include<iostream>
using namespace std;
struct date
{
 int dd, mm, yyyy;
 date *ptr;
};
int main()
{
 date *ptr;
 ptr=new date;
 ptr->dd=28;
 ptr->mm=6;
 ptr->yyyy=1983;
 cout<<"Your date of Birth is "<<ptr->dd<<"/"<<ptr->mm<<"/"<<ptr->yyyy;
 delete ptr;
}

Here date is a data type created by the user, and ptr is a pointer of this type.

Exam Tips:

a) Mention that the structure name (tag) can be used like int or float to declare variables.
b) Support the statement with a small, correct example.

 

Question 21: Read the following statements:
i) While defining a structure in C++, the tag may be omitted.
ii) The data contained in a structure variable can be copied into another variable only if both of them are declared using the same structure tag.
iii) Elements of a structure are referenced by structure_name.element
iv) A structure can contain another structure.
Now, choose the correct option from the following:
a) Statements (i) and (ii) are true
b) Statements (ii) and (iv) are true
c) Statements (i), (ii) and (iv) are true
d) Statements (i) and (iii) are true

Answer:

c) Statements (i), (ii) and (iv) are true.
Statement (iii) is false because the elements of a structure are referred to by the structure variable name followed by the dot operator, that is, variable_name.element, and not by the structure name.

Exam Tips:

a) Check every statement separately before choosing the option.
b) The dot operator is always used with a structure variable, not with the structure tag.

 

Question 22: Read the following C++ statements:
int *p, a=5;
p=&a;
a) What is the speciality of the variable p?
b) What will be the content of p after the execution of the second statement?
c) How do the expressions *p+1 and *(p+1) differ?

Answer:

a) p is a special variable called a pointer; it stores the address of another variable.
b) p contains the address of the variable a.
c) *p+1 gives the value of a plus 1, that is, 5+1 = 6.
*(p+1) gives the content of the next memory location after a. Here p+1 is (address of a) + 4 (4 is the size of the int data type in the compiler used), and *(p+1) is the value stored at that address.

#include<iostream>
using namespace std;
int main()
{
 int *p, a=5;
 p=&a;
 cout<<*p+1<<endl;
 cout<<*(p+1);
}

Exam Tips:

a) Remember that *p+1 adds 1 to the value, while *(p+1) moves the address to the next integer location first.
b) The size of int may differ with the compiler, so write "size of the int data type" in the answer.

 

Question 23: Identify the errors in the following C++ code segment and give the reason for each.
int p, *q a=5;
float b=2;
p=&a;
q=&b;
cout<<p<<*p<<*a;
if (p<q) cout<<p;
cout<<p *a;

Answer:

Following are the errors:
1) The declaration is wrong: p is declared as a normal integer variable and not as a pointer, and a comma is missing before a=5.
2) Here q is an integer pointer, so it cannot store the address of the float variable b.
3) *a cannot be printed, because a is not a pointer.
4) The pointers p and q are of different types, so they cannot be compared with the relational operator.
The correct code is given below.

#include<iostream>
using namespace std;
int main()
{
 int *p, a=5, *q, b=2;
 p=&a;
 q=&b;
 cout<<p<<*q<<*p;
 if(p!=q)
  cout<<p;
 cout<<*p*a;
}

Exam Tips:

a) Read the code line by line and write each error with its reason.
b) The * operator can be used only with pointer variables.
c) A pointer can store only the address of a variable of its own type.

 

Question 24: While writing a program, the concept of dynamic memory allocation is applied. But the program does not contain a statement with the delete operator and it creates a problem. Explain the problem.

Answer:

If the memory allocated using the new operator is not de-allocated using delete, that memory is left unused and is not released for further allocation. Such memory blocks are called orphaned memory blocks.
On each execution the amount of orphaned memory increases. This situation is called a memory leak.

Exam Tips:

a) Use the terms "orphaned memory" and "memory leak" in the answer.
b) Add that the delete operator avoids the problem.

 

Question 25: Read the C++ statements given below and answer the following questions:
int ar[] = {34, 12, 25, 56, 38};
int *p = ar;
a) What will be the content of p?
b) What is the output of the expression: *p + *(ar+2)?
c) The statement ar++; is invalid. Why? How does it differ from p++;?

Answer:

a) p contains the starting address of the array ar, that is, the address of the first element (the element it points to is 34).
b) *p = 34 and *(ar+2) = 25
So *p + *(ar+2) = 34 + 25 = 59.
c) The array name ar is a constant pointer, so its value cannot be changed and ar++ is invalid. But p is a pointer variable, so p++ is valid; it makes p point to the next element of the array.

Exam Tips:

a) Remember that the array name holds the address of the first element.
b) The array name is a constant pointer, so increment and decrement operations are not allowed on it.

 

Question 26: Explain the working of the following code segment and predict the output:
char *str = "Tobacco Kills";
for (int i=0; str[i] != '\0'; i++)
 if (i>8)
  *(str+i) = toupper(*(str+i));
cout<<str;

Answer:

The output is "Tobacco KILLS".
The loop visits every character of the string. When the index i is greater than 8, that is, from the character at index 9 (the tenth character) onwards, the toupper() function converts the character to upper case.

Exam Tips:

a) Count the index from 0 when tracing such loops.
b) State the output clearly and explain which characters change.

 

Question 27: Observe the following C++ statements:
int ar[] = {14, 29, 32, 63, 30};
One of the following expressions cannot be used to access the element 32. Which is that?
a) ar[2]
b) ar[*ar%3]
c) *ar+2
d) *(ar+2)

Answer:

c) *ar+2
*ar gives 14, so *ar+2 gives 14+2 = 16, which is not the element 32.
(In option b, *ar%3 = 14%3 = 2, so ar[2] = 32.)

Exam Tips:

a) Evaluate each option one by one instead of guessing.
b) *ar+2 adds 2 to the value, while *(ar+2) reads the third element.

 

Question 28: Explain the operations performed by the operators new and delete with the help of examples.

Answer:

The new operator is used to allocate memory dynamically.
Syntax:
pointer_variable = new data_type;
Example:

int n, *ptr1;
ptr1=new int;

The delete operator is used to de-allocate the memory allocated by the new operator.
Syntax:
delete pointer_variable;
Example: delete ptr1;
Example program:

#include<iostream>
using namespace std;
int main()
{
 int n, *ptr1;
 ptr1=new int(10);
 cout<<"The content of the memory is "<<*ptr1;
 delete ptr1;
}

Exam Tips:

a) Give the syntax and a small example for both operators.
b) new returns the address of the allocated memory; delete releases it.

 

Question 29: What is meant by memory leak? What are the reasons for it? How can we avoid such a situation?

Answer:

If the memory allocated using the new operator is not de-allocated using delete, that memory is left unused and is not released for further allocation. Such memory blocks are called orphaned memory blocks.
On each execution the amount of orphaned memory increases. This situation is called a memory leak.
Reason: memory that is allocated dynamically with new is not released with delete.
Use the delete operator to avoid this.

Exam Tips:

a) Define the term first, then give the reason and the remedy as asked in the three parts of the question.

 

Question 30: Compare the following two statements:
int a=5;
int *a=new int(5);

Answer:

int a=5; This means that 'a' is an integer variable that is initialised with the integer value 5.
int *a=new int(5); Here 'a' is a pointer variable. It allocates memory dynamically for an integer, stores the value 5 in it, and holds the address of that memory.

Exam Tips:

a) Point out that the first one is an ordinary variable and the second is a pointer to dynamically allocated memory.
b) Add that memory created with new must be released with delete.

 

Question 31: Read the structure definition given below and answer the following questions:
struct sample
{
 int num;
 char *str;
} *sptr;
a) Write C++ statements to dynamically allocate a location for sample type data and store its address in sptr.
b) Write C++ statements to input data into the location pointed to by sptr.
c) Modify this structure into a self-referential structure.

Answer:

a) sptr = new sample;
b)

cin>>sptr->num;
cin>>sptr->str;

Example:

#include<iostream>
using namespace std;
struct sample
{
 int num;
 char *str;
} *sptr;
int main()
{
 sptr=new sample;
 sptr->str=new char[20];
 cout<<"Enter value for num:";
 cin>>sptr->num;
 cout<<"Enter value for str:";
 cin>>sptr->str;
 cout<<sptr->num<<sptr->str;
}

c)

struct sample
{
 int num;
 char *str;
 sample *sptr;
};

Exam Tips:

a) Use the arrow operator (->) to reach the members through a structure pointer.
b) A self-referential structure contains a pointer to its own type.

 

Kerala Board Solutions for Class 12 Computer Science Chapter 01 Structures and Pointers

Textbook Solutions for Class 12 Computer Science Chapter 01 Structures and Pointers

Review comprehensive exercise answers for Class 12 Computer Science Chapter 01 Structures and Pointers. Fully updated to match current Kerala Board syllabus guidelines, these textbook solutions help students verify their work and maintain accurate study notes.

Mastering Theoretical and Practical Questions

Clear, methodical explanations accompany every challenging problem within the Class 12 Computer Science text. Engaging with these detailed answers lays a solid foundation for advanced learning and improves foundational clarity for upcoming assessments.

Effective Self-Study and Homework Assistance

These resources act as an effective roadmap for daily homework tasks and independent study. Supplement your review of Chapter 01 Structures and Pointers with official sample papers and interactive practice tests available on our platform free of charge.

FAQs

Where can I find the latest Kerala Plus Two Computer Science Previous Questions Chapter 1 Structures and Pointers for the 2026-27 session?

The complete and updated Kerala Plus Two Computer Science Previous Questions Chapter 1 Structures and Pointers is available for free on StudiesToday.com. These solutions for Class 12 Computer Science are as per latest Kerala Board curriculum.

Are the Computer Science Kerala Board solutions for Class 12 updated for the new 50% competency-based exam pattern?

Yes, our experts have revised the Kerala Plus Two Computer Science Previous Questions Chapter 1 Structures and Pointers as per 2026 exam pattern. All textbook exercises have been solved and have added explanation about how the Computer Science concepts are applied in case-study and assertion-reasoning questions.

How do these Class 12 Kerala Board solutions help in scoring 90% plus marks?

Toppers recommend using Kerala Board language because Kerala Board marking schemes are strictly based on textbook definitions. Our Kerala Plus Two Computer Science Previous Questions Chapter 1 Structures and Pointers will help students to get full marks in the theory paper.

Do you offer Kerala Plus Two Computer Science Previous Questions Chapter 1 Structures and Pointers in multiple languages like Hindi and English?

Yes, we provide bilingual support for Class 12 Computer Science. You can access Kerala Plus Two Computer Science Previous Questions Chapter 1 Structures and Pointers in both English and Hindi medium.

Is it possible to download the Computer Science Kerala Board solutions for Class 12 as a PDF?

Yes, you can download the entire Kerala Plus Two Computer Science Previous Questions Chapter 1 Structures and Pointers in printable PDF format for offline study on any device.