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

DPS - Modern Indian School Doha, Qatar Pointers Worksheet: Class XII Name

This document contains 19 questions about pointers and arrays in C++. The questions cover topics like pointer declarations and definitions, dynamic vs static memory allocation, passing arrays and pointers to functions, pointer arithmetic, and manipulating strings using pointers. Students are asked to write code snippets, find outputs, correct syntax errors, and explain differences between pointer-related concepts.

Uploaded by

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

DPS - Modern Indian School Doha, Qatar Pointers Worksheet: Class XII Name

This document contains 19 questions about pointers and arrays in C++. The questions cover topics like pointer declarations and definitions, dynamic vs static memory allocation, passing arrays and pointers to functions, pointer arithmetic, and manipulating strings using pointers. Students are asked to write code snippets, find outputs, correct syntax errors, and explain differences between pointer-related concepts.

Uploaded by

maya__scribd
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

DPS Modern Indian School

Doha, Qatar
Pointers Worksheet
Class XII

Name: _________________

1. Find mistakes, if any, in the following definition and make necessary correction:
char S[10], *ptr = S[6];

_________________________________________
_____
2. Distinguish between: int *ptr = new int(5); and int *ptr = new int[5];

_________________________________________
_________________________________________
_________________________________________
_______________
3. Consider the following program
void main( )
{ int x[10], i, *px=x, *py = &x[5];
i = py-(px++);
}
What is the value of i?
(a) 4

(b) 5

(c) 6

(d) 10.

4. How are the declarations int *p; and int **p; different?

_________________________________________
_________________________________________
Page 1 of 11

_________________________________________
_________________________________________
_________________________________________
_________________________
5. Rewrite the following declaration, without errors and underlining the corrections made:
float **P1, *p2=&p1;

_________________________________________
_________________________________________
__________
6. Differentiate between static and dynamic allocation of memory.

Static

Dynamic

1
2
3

7. Define a pointer. What is the relationship between an array and a pointer? Given below is a
function to traverse a character array using for-loop. Use pointer notation in place of array
notation and substitute for-loop with while-loop so that the output of the function stringlength()
remains the same.

int strlength(char s[])


{ int count=0;
for(int x=0; s[x];

x++,count++);

return (count);
}

_________________________________________
_________________________________________
Page 2 of 11

_________________________________________
_________________________________________
_________________________________________
_________________________________________
_________________________________________
_________________________________________
_________________________________________
_________________________________________
____
8. What will be the output of following code fragment:
void main()
{ int a[ ]={ 3, 5, 6 , 7}, *p=a;
cout<<*p<< \t<<*(p+2)<< \t<<*p++;
}

_________________________________________
_____
9. Give the output of the following program segment. (Assume required header files are
#included):
char *s = SUPER;

___________________________
___________________________
for (int x=strlen(s)-1; x>=0; x--)
___________________________
{ for(int y=0; y<=x; y++)
___________________________
___________________________
cout<<s[y];
_______________
cout<<endl;
}

10. Give the output of the following code. (Assuming header files are #included):
Page 3 of 11

char

*NAME= a ProFile;

_______________
for (int x=0; x<strlen (NAME); x++)
if (islower(NAME[x]))
NAME[x]=toupper(NAME[x]);
else if (isupper(NAME[x]))
if (x %2!=0)
NAME[x]=tolower(NAME[x-1]);
else
NAME[x]--;
cout<<NAME<<endl;

11. Re-write after correcting syntax error(s), if any. Underline the corrections made.
void main( )
{ const int i=20;
const int *ptr=&i;
*ptr++;
int j=15;
ptr=&j;

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
________________________

12. Give the output of the following. (Assume all required header files are #included):
void main( )
{ int a=32, *X=&a;
char ch=65, &cho=ch;
cho += a;
*X += ch;
Page 4 of 11

__________________
__

cout << a << , << ch << endl;


}

13. Give the output of the following program segment (Assume header files are #included):
void main( )
{ int array[ ]={2,3,4,5}, *arptr=array;
int value=* arptr;

cout << value <<

"

";

value=*arptr++;

cout << value <<

"

";

value=*arptr;

cout << value <<

"

";

value=* ++arptr;

cout << value;

_________________________________________
14. Find the output of the following program :void main( )
{ int x[]={10,25,30,55,110}, *p=x;
while (*p<110)
{ if(*p%3 !=0)
*p=*p+1;
else
*p=*p+2;
p++;
}
for (int i=4; i>=1; i--)
{ cout<<x[i]<< "*";
if (i % 3==0)
cout<<endl;
}
Page 5 of 11

cout<<x[0]*3<<endl;
}

_________________________________________

Page 6 of 11

15. WAP to input a string and copy it onto another. The strings are passed to a UDF, which copies
the strings character by character. Do not use any std. library functions.

__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
_______________________
16. Write a function that takes two strings arguments and returns the string whose ASCII value is the
greater at the 1st differing position. Test the function by calling it from main() with 2 parameters.

__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
Page 7 of 11

__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
_
__________________________________________
_____
17. Write a program to test whether an input string is a palindrome or not. (Use pointer notation).

__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
Page 8 of 11

__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
_______________________________
18. WAP to accept a string and a character and print the number of times the character occurs in the
string.

Page 9 of 11

__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________

19. WAP to create a 3*4 integer array with some initial values. Print the address of each element in
tabular form. Also print the value of each element in tabular form. (Use pointer notation)

__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
Page 10 of 11

__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
__________________________________________
______

Page 11 of 11

You might also like