0% found this document useful (0 votes)
37 views2 pages

Cbs:Pv:Xii:Assignment - 5: Pointers

This document contains 20 questions related to pointers in C++. It covers topics like pointer declaration and initialization, dynamic memory allocation, reference variables, functions returning pointers, accessing structure members using pointers, pointer arithmetic, self-referential structures, and memory leaks. It also contains questions testing pointer concepts like differences between pointers to constants vs constant pointers, use of this pointer, and programs to find largest element in an array, check for palindromes, and count characters using pointers.

Uploaded by

Niti Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Cbs:Pv:Xii:Assignment - 5: Pointers

This document contains 20 questions related to pointers in C++. It covers topics like pointer declaration and initialization, dynamic memory allocation, reference variables, functions returning pointers, accessing structure members using pointers, pointer arithmetic, self-referential structures, and memory leaks. It also contains questions testing pointer concepts like differences between pointers to constants vs constant pointers, use of this pointer, and programs to find largest element in an array, check for palindromes, and count characters using pointers.

Uploaded by

Niti Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CBS:PV:XII:ASSIGNMENT 5 : POINTERS

1. What is a pointer? What are the arithmetic operations, one can perform on a
pointer variable? Explain using suitable examples.
2. How will you declare and initialize a pointer? Give suitable example.
3. What do you understand by dynamic memory allocation/deallocation? What are
the merits and demerits of static and dynamic memory allocation?
4. Define variable, array and pointer.
5. Explain reference variables and use of alias with some suitable examples.
6. What do you understand by function returning a pointer? Give suitable example in
support of your answer.
7. Explain the function call by reference giving a suitable example in support of
your answer.
8. How can you access the members of a s structure using a pointer variable pointing
to that structure?
9. What is the utility of dereference operators? Explain using suitable examples.
10. What are self referencial structures? Explain by giving suitable example.
11. What is the difference between pointers to constants and constant pointer? Give
examples.
12. iiustrate the use of this pointer with the help of an example.
13. Write a C++ program to find the largest element in an array using pointers?
14. Write a C++ program to accept a string and check if it is a palindrome using
pointers.
15. Write a C++ program to accept a string and a character and print the number of
times the character has occurred in the string using pointers.
16. What do you mean by memory leaks? What are the possible reasons for it? How it
can be avoided?
17. A C++ program contains the following declaration:
static int x[8]={10,20,30,40,50,60,70,80};
i)
What is the meaning of x?
ii)
What is the meaning of (x+2)?
iii)
What is the value of *x?
iv)
What is the value of (*x+2)?
v)
What is the value of *(x+2)?
18. Give the output of the following:
#include<iostream.h>
#include<string.h>
class per
{ char name[20];
float age;
public:
per(char *s,float a)
{ strcpy(name,s);age=a;}
per *gr(per &x)
{ if(x.age>=age)
return x;
else
return *this;
}

void display()
{
cout<< Name :<<name<<\n;
cout<< Age : <<age<<\n;
}
};
void main()
{
per p1(RAMU,27.5),p2(RAJU,53),p3(KALU,40);
per p(\0,0);
p=p1.gr(p3);p.display();
p=p2.gr(p3);p.display();
}
19. Give the output :
#include<iostream.h>
#include<conio.h>
int a=10;
void main()
{
void demo(int &,int, int *);
clrscr();
int a=20,b=5;
demo(::a,a,&b);
cout<<::a<< \t<<a<< \t<<b<<endl;
}
void demo(int &x, int y,int *x)
{
a+=x;y*=a;*z=a+y;
cout<<x<< \t<<y<< \t<<*z<<endl;
20. Give the output:
i)
char *s= GOODLUCK;
for(int x=strlen(s)-1;x>=0;x--)
{ for(int y=0;y<=x;y++)
cout<<s[y];
cout<<endl;
}
ii)
void main()
{
int a=32,*x=&a;
char ch=65, &cho=ch;
cho+=a;
*x+=ch;
cout<<a<< ,<<ch<<endl;
}
*******************

You might also like