2nd PUC Computer Science Question Bank Chapter 11 Pointers

Students can Download 2nd PUC Computer Science Chapter 11 Pointers Questions and Answers, Notes Pdf, 2nd PUC Computer Science Question Bank with Answers helps you to revise the complete Karnataka State Board Syllabus and to clear all their doubts, score well in final exams.

Karnataka 2nd PUC Computer Science Question Bank Chapter 11 Pointers

2nd PUC Computer Science Pointers One Mark Questions and Answers

Question 1.
What do you mean by pointer?
Answer:
A Pointer is a variable that holds a memory address, usually the location of another variable in memory.

2nd PUC Computer Science Question Bank Chapter 11 Pointers

Question 2.
Mention any one advantage of pointer?
Answer:

  1. It is possible to write efficient programs.
  2. Memory is utilized properly.
  3. Dynamically allocate & deallocate the memory.
  4. Eary to deal with the hardware components.

Question 3.
What is address operator?
Answer:
Is address operator, it is a unary operator that returns the memory address of its operand.

Question 4.
What is pointer operator?
Answer:
Is a pointer, it is a unary operator that returns the value of the variable pointed by the pointer.

Question 5.
How to declare pointer?
Answer:
data type * variable – name ; data – type is any valid data type supported by C++ or any other user defined readed variable name is the name of the pointer variable.

Question 6.
How to initialize pointer?
Answer:
Int num = 25;
Int iptr;
iptr = & num;

Question 7.
What is static memory?
Answer:
In the static memory allocation, the amount of memory to be allocated is predicted & pre-known this memory to be allocated is predicted & pre-known. This memory is allocated during the compilation itself. Ex: Int a;

2nd PUC Computer Science Question Bank Chapter 11 Pointers

Question 8.
What is dynamic memory?
Answer:
In the dynamic memory allocation, the amount of memory to be allocated is not known. This memory is allocated during run-time as and when required.

Question 9.
What is free store?
Answer:
Free store is a pool of unallocated memory heap given to a program that is used by the program for dynamic allocation during execution.

Question 10.
Write a definition for a variable of type pointer to float.
Answer:
Float, Fptr.

Question 11.
What is new operator in C++?
Answer:
We can allocate storage for a variable while program is running by using new operator.

Question 12.
What is delete operator in C++?
Answer:
Delete operator is used to free dynamic memory.

2nd PUC Computer Science Pointers Two Marks Questions and Answers

Question 1.
What do you mean by pointer? Explan with example.
Answer:
A pointer is a variable that holds a memory address, usually the lacation of another variable in memory. Pointer is declared as follows.
Data – type * variable – name:
data -type is any valid data type supported by C++ or ony other user defined typeabd variable name is the name of the pointer variable.
Ex:
int num =25;
int * iptr;
iptr = & num;

Question 2.
Mention any two advantages of pointer.
Answer:

  1. It is possible to write efficient programs.
  2. Memory is utilized properly.
  3. Dynamically allocate & deallocate the memory.
  4. Easy to deal with the hardware components.
  5. Establishes the communication between program & data.

2nd PUC Computer Science Question Bank Chapter 11 Pointers

Question 3.
What is address operator? Give Example.
Answer:
The ampersand symbol (&) is address operator, it is a unary operator that return the memory address of its operand.
Ex:
int num = 25;
int * iptr;
iptr = & num;

Question 4.
What is pointer operator? Give example.
Answer:
The asterisk (*) is a pointer operator, it is a unary operator that return the value of the variable pointed by the pointer.

Ex:
# include < iosleram. h>
# include < iomanip. h>
void main ()
{
int var;
int * ptr;
int val;
var = 3000;
ptr = & var;
val = * ptr;
cout<<"value of var, "<<var<< end |;
cout<<"value of ptr; "<<ptr«end |;
cout <<"value of val; << val << end |;
}

Question 5.
How to declare pointer? Give Example.
Answer:
data-type * variable-name;
data-type is any valid data type supported by C++ or any other user defined type and variable name is the name of the pointer variable.
Ex:
int * iptr;
float * fptr;
char * cptr;

Question 6.
How to initialize pointer? Give example?
Answer:
int num = 25;
int * iptr;
iptr = & num;

Question 7.
What is static memory?
Answer:
Static memory allocation is the amount of memory to be allocated which is predicted and preknown. This memory is allocated during the compilation itself. All the declared variables declared normally, are allocated memory statically.
Example: int a; // Allocates 2 bytes of memory space during // compilation time.

Question 8.
What is dynamic memory?
Answer:
In the dynamic memory allocation, the amount of memory to be allocated is not known. This memory is allocated during run – time as and when required.
Example: int * p Number;
pNumber = new int;
The first line declares the pointer, P Number. The second line then allocates memory for an integer and then makes PNumber point to this new memory.

2nd PUC Computer Science Question Bank Chapter 11 Pointers

Question 9.
What is free store?
Answer:
Free store (heap memory) is a pool of unallocated memory heap given to a program that is used by the program for dynamic allocation during execution.

Question 10.
Illustrate the use of “self referential structure” with the help of example.
Answer:
The self referential structures are structures that include an element that is a pointer to another structure of the same type.
Struct node
{
into data;
node* next;
}

Question 11.
What is new operator in C++?
Answer:
In C++ the new operator allocates memory dynamically.
Example: Pointer variable = new data type.

Question 12.
What is delete operator in C++?
Answer:
The delete operator in C++ releases dynamically allocated memory.

Question 13.
What is an array of pointers? Give example.
Answer:
An array of address means that its a collection of address.
For example below shows the array of pointers.
int*iptr [5];
int i = 10, J = 20, K = 30, l = 40, m = 50;
iptr[0] = & i; * iptr [0] = 10;
iptr [1] = & j; * iptr [1] = 20;
iptr [2] = &k; * iptr [2] = 30;
iptr [3] = &l; * iptr [3] = 40;
iptr [4] = & m; * iptr [4] = 50;

2nd PUC Computer Science Pointers Three Marks Questions and Answers

Question 1.
What are the advantages of pointers?
Answer:

  1. It is possible to write efficient programs.
  2. Memory is utilized properly.
  3. Dynamically allocate & deallocate the memory.
  4. Easy to deal with the hardware components.
  5. Establishes the communication between program & data.

2nd PUC Computer Science Question Bank Chapter 11 Pointers

Question 2.
How dynamic memory allocation is different from static memory allocation.
Answer:
Static Memory Allocation:

  1. Memory is allocated before the execution of the program begins. [During the compilation]
  2. No Memory allocation or deallocation action are performed during the execution.
  3. Variable remain permanently allocated.
  4. Implemented using stack & heaps.

Dynamic Allocation of Memory:

  1. Memory is allocated during the execution of the program.
  2. Memory Bindings are established & destroyed during the execution.
  3. Allocated only when program unit is active.
  4. Implemented using data segments.

Question 3.
Illustrate the use of “self-referential structures” with the help of example.
Answer:
The “Self referential structures” are structures that include an element that is a pointer to another structure of the same type.
Example:
Struct node
{
int data;
node * next;
}

Question 4.
What is new operator in C++? Give example.
Answer:
We can allocate storage for a variable while program is running by using new operator. Dynamic allocation is perhaps the key to pointers. It is used to allocate memory without having to define variable & then make pointers point to them.

2nd PUC Computer Science Question Bank Chapter 11 Pointers

Question 5.
What is delete operator in C+++? Give example.
Answer:
Delete operator is used to free dynamic memory as delete iptr;
To free dynamic array memory, delete []dptr;
To free dynamic structure, delete student;

Question 6.
Show the general form new and delete operator in C++?
Answer:

# include < iostream. h >
# include < conio. h >
# include < iomain p.h>
int * p
void some function ()
{
// make P pointer point to a new integer
p = new int;
*p = 25;
}
void main ()
{
some function (); // make p Pointer point to something
cout < < "value of *p : " << * p ;
out put value of *p ; 25
}

Question 7.
What is array of pointers? Give example.
Answer:
An array of pointers means that it is a collection of addresses.
Example:
int * iptr [5]
int i = 10, j = 20, k = 30, l = 40, m = 50;
iptr [0] = & i; *iptr [0] = 10
iptr [1] = & j; *iptr [1] = 20
iptr [2] = & k; * iptr [2] = 30
iptr [3] & l; * iptr [3] = 40
iptr [4] & M; * iptr [4] = 50

Question 8.
What is the relationship between array & pointers? Give example.
Answer:
Consider a declartion int a [6]; The element of the array can be referred to in the program as a [0], a[l], a[2]….a[5]. When the program is compiled, the compiler does not save the address of all the elements, but only the address of the first element, a[0].

When the, program needs to access any element, a[i], it calculates the address by adding i units, tp the address of a[0]. The number of bytes in each unit is in our example, equals to the size of (int). i.e, 2. In general. It is equal to the number of bytes required to store am elment of array.

2nd PUC Computer Science Question Bank Chapter 11 Pointers

Question 9.
What is the relationship between string & pointers? Give example.
Answer:
Suppose we have declared an array of 5 elements of the data type character.
char s [5] ;
char * cptr;
cptr = s;
Here, S is array of characters [Strings] cptr is character pointer to string S gives the base address of the array i, e., the address of the first character in the string variable & hence can be regarded as pointer to character.

Question 10.
What is the relationship between structure & pointers? Give Example.
Answer:
We can create pointers to structure variables.
struct student
{
int rollno;
float fees;
}
Student s;
Student * SP = &s;
(*Sp) rollno = 104;
The above statements can be written using the operator → as
ptr → member;
Sp → rollno = 104;

2nd PUC Computer Science Question Bank Chapter 11 Pointers

Question 11.
What is the relationship between object & pointers? Give Example.
Answer:
The pointers pointing to the object are referred as object pointers declaration of the object pointers.
class – name * object – pointer;
Here, class-name is the name of an already declared defined class & object- pointer is the pointer to an object of the classtype.
Ex:- employee * eptr;
Here employee is an already defined class, when accessing members of a class using an object pointer, the arrow pointer (→) is used instead of dot. (.) operator.
The following program illustrates how to access an object given a pointer to it.
# include < iostream. h>
# include < iomanip.h>
# include < conio.h >
class emp
{
Private:
2nd PUC Computer Science Question Bank Chapter 11 Pointers 1
2nd PUC Computer Science Question Bank Chapter 11 Pointers 2

2nd PUC Computer Science Pointers Five Marks Questions and Answers

Question 1.
Show the general form new and delete operator in C++?
Answer:

# include < iostream. h >
# include < conio. h >
# include < iomain p.h>
int * p
void some function ()
{
// make P pointer point to a new integer
p = new int;
*p = 25;
}
void main ()
{
some function (); // make p Pointer point to something
cout < < "value of *p : " << * p ;
out put value of *p ; 25
}

2nd PUC Computer Science Question Bank Chapter 11 Pointers

Question 2.
What is the relationship between object and pointers? Give example.
Answer:
The pointers pointing to the object are referred as object pointers declaration of the object pointers.
class – name * object – pointer;
Here, class-name is the name of an already declared defined class & object- pointer is the pointer to an object of the classtype.
Ex:- employee * eptr;
Here employee is an already defined class, when accessing members of a class using an object pointer, the arrow pointer (→) is used instead of dot. (.) operator.
The following program illustrates how to access an object given a pointer to it.
# include < iostream. h>
# include < iomanip.h>
# include < conio.h >
class emp
{
Private:
2nd PUC Computer Science Question Bank Chapter 11 Pointers 3
2nd PUC Computer Science Question Bank Chapter 11 Pointers 4

Question 3.
Explain with example by passing the reference.
Answer:
When parameters are passed to the functions by reference the formal parameters become reference (or aliases) to the actual parameters in the calling function. This means that invoking the called function refers to the original value by different names i,e; their references. Thus the called functions works with the original data & any change in the values gets reflected to the data.

The call by reference method is useful in situation where the values of the original v ariable are to be change d using the function. Say for instances a function is to be invoked that swap of two variable that are parsed by references. The following example program explains.
2nd PUC Computer Science Question Bank Chapter 11 Pointers 5
x = y;
y = temp;
}

2nd PUC Computer Science Question Bank Chapter 11 Pointers

Question 4.
Explain with example by passing the pointers.
Answer:
When the pointers are passed to functions, the addresses of actual arguments in the calling function are copied into the formal arguements (the address of original values) in the called functions. We can make the changes into the actual arguments of the calling function, therefore here also, the called fanction does not create own copy of original values rather, it refers to the original values by the address (passed through pointers) it recieves.

To swap two values, we have seen how the passing references method works. The same can be achived by passing address through pointers. The following programming example:
2nd PUC Computer Science Question Bank Chapter 11 Pointers 6