0% found this document useful (0 votes)
31 views

Xii:Assignment - Pointers

The document discusses pointers in C++. It provides 13 questions about pointers, including how to declare and initialize pointers, pointer arithmetic, accessing structure members using pointers, returning pointers from functions, call by reference, memory leaks, and examples of pointer programs to find the largest element in an array, check if a string is a palindrome, and count the occurrences of a character in a string. It also provides two code snippets and asks for their output.

Uploaded by

Dhruv Khrra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Xii:Assignment - Pointers

The document discusses pointers in C++. It provides 13 questions about pointers, including how to declare and initialize pointers, pointer arithmetic, accessing structure members using pointers, returning pointers from functions, call by reference, memory leaks, and examples of pointer programs to find the largest element in an array, check if a string is a palindrome, and count the occurrences of a character in a string. It also provides two code snippets and asks for their output.

Uploaded by

Dhruv Khrra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

XII:ASSIGNMENT – 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. Define variable, array and pointer.
4. Explain reference variables and use of alias with some suitable examples.
5. What do you understand by function returning a pointer? Give suitable example in
support of your answer.
6. Explain the function call by reference giving a suitable example in support of your
answer.
7. How can you access the members of a s structure using a pointer variable pointing to that
structure?
8. Illustrate the use of this pointer with the help of an example.
9. Write a C++ program to find the largest element in an array using pointers?
10. Write a C++ program to accept a string and check if it is a palindrome using pointers.
11. 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.
12. What do you mean by memory leaks? What are the possible reasons for it? How it can be
avoided?
13. 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)?
14. 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();
}
15. 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 *z)
{
a+=x;y*=a;*z=a+y;
cout<<x<< ‘\t’<<y<< ‘\t’<<*z<<endl;
16. 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