II-202 Programming Concepts
32. The pointer can hold the address of
(a) a variable (b) address of address of a variable and so on
(c) points to a particular memory location (d) All of these
33. Which is incorrect
(a) The pointer is variable and cannot be made constant
(b) One type of pointer cannot hold the data with other data type
(c) The value in one location cannot be copied to another location using pointer
(d) All of these
34. Which segment is valid
(a) char *names[] = {"Rahul","Sachin"};
(b) char *names = {"Rahul","Sachin"};
(c) char **names = {"Rahul","Sachin"};
(d) All are valid
35. Choose the correct output.
void main()
{
int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},
{3,4}}};
clrscr();
printf("%u %u %u %d ",a,*a,**a,***a);
getch();
}
(Assume the starting address 2000)
The output is
(a) 2000 2000 2000 2 (b) 2000 2002 2002 2
(c) 2000 2002 2004 2 (d) 2000 2 2 2
36. Choose the correct output.
void main()
{
int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}
};
clrscr();
printf("%u %u %u %d ",a+1,*a+1,**a+1,***a+1);
getch();
}
(Assume the starting address 2000)
M09_ITL-ESL4791_02_SE_C09.indd 202 12/22/2012 5:04:02 PM
Pointers II-203
The output is
(a) 2012 2004 2002 3 (b) 2024 2008 2002 2002
(c) 2024 2004 2002 3 (d) 2012 2008 2002 2002
Answers
1. (a) 2. (c) 3. (b) 4. (a) 5. (a) 6. (a) 7. (a) 8. (a) 9. (a) 10. (b)
11. (a) 12. (a) 13. (a) 14. (a) 15. (a) 16. (a) 17. (a) 18. 19. (a) 20. (a)
21. (b) 22. (a) 23. (b) 24. (a) 25. (a) 26. (a) 27. (b) 28. (a) 29. (a) 30. (b)
31. (a) 32. (d) 33. (d) 34. (a) 35. (a) 36. (a)
True or False
1.  Memory space required for pointers of any data type is the same.
2.  A pointer is a memory variable that stores memory address of another variable.
3.  Pointers can be used to represent arrays.
4.  The indirection operator (*) is used to identify the pointer variable.
5.  The ‘&’ is an address operator and represents the address of the variable.
6.  The physical memory locations of the variable is system dependent.
7.  The user can predict  the address of the  memory variable.
8.  The pointer of any data type itself requires only four bytes.
9.  A pointer cannot point to another pointer variable.
10.  The address of aninteger a is 4044 andafterincrementinga’s value by one,the address becomes4046.
11.  The pointer variable holding address of another pointer is pointer to pointer.
12.  p**  is pointer to pointer.
13.  *p is a pointer.
14.  char **q is pointer to pointer.
Answers
1.  True 2.  True 3.  True 4.  True 5.  True 6.  True 7.  False 8.  True 9.  False
10.  False 11.  True 12.  False 13.  True 14.  True
M09_ITL-ESL4791_02_SE_C09.indd 203 12/22/2012 5:04:03 PM
II-204 Programming Concepts
Additional Questions
What is/are the output/s of the following programs?
1.  Use pointer and display value and address of an integer element
#include <stdio.h>
#include <conio.h>
void main()
{
int num=10,*p;
p=&num;
clrscr();
printf("%d",*p);
printf("%d",num);
printf("%u",&num);
printf("%u",p);
getche();
}
OUTPUT:
10 10 65498 65498
2. Use pointer and display a number  
#include <stdio.h>
#include <conio.h>
void main()
{
int p=10;
void *pt=&p;
clrscr();
*(int*)pt=12;
printf("%d",p);
}
OUTPUT:
12
M09_ITL-ESL4791_02_SE_C09.indd 204 12/22/2012 5:04:03 PM
Pointers II-205
3. Use pointer and display number by different ways
void main()
{
int t=10,*p;
clrscr();
p=&t;
printf(" t = %d t = %d t = %d",t,*(&t),*p);
}
OUTPUT:
t = 10 t = 10 t = 10
4. Use pointers and  display long integers and floating point numbers
#include <stdio.h>
#include <conio.h>
void main()
{
long int a,*pa;
float b,*pb;
clrscr();
printf("Enter Integer & float Value :");
scanf("%ld %f",&a,&b);
pa=&a;
pb=&b;
printf(" Address of a=%u",pa);
printf(" Value of a=%ld",a);
printf(" Value of a=%ld",*(&a));
printf(" Value of a=%ld",*pa);
printf(" Address of b=%u",pb);
printf(" Value of b=%.2f",b);
printf(" Value of b=%.2f",*(&b));
printf(" Value of b=%.2f",*pb);
}
OUTPUT:
Enter integer and float value :2345 2.345
Address of a = 65492
Value of a = 2345
Value of a = 2345
Value of a = 2345
Address of b = 65496
Value of b = 2.35
Value of b = 2.35
Value of b = 2.35
M09_ITL-ESL4791_02_SE_C09.indd 205 12/22/2012 5:04:03 PM
II-206 Programming Concepts
5. Display the memory requirement for character, integer and float numberand their pointers.
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
printf("char %d byte & its pointer %d bytes
n",sizeof(char),sizeof(char*));
printf("int %d byte & its pointer %d bytes
n",sizeof(int),sizeof(int*));
printf("float %d byte & its pointer %d
bytes ",sizeof(float),sizeof(float*));
}
OUTPUT:
char 1 byte and its pointer 2 bytes
int 2 byte and its pointer 2 bytes
float 4 byte and its pointer 2 bytes
6.  Program on display of a string using pointer
#include <stdio.h>
#include <conio.h>
void main()
{
char c[]="India";
char *p;
p=c;
clrscr();
printf("%s",p);
}
OUTPUT:
India
7. Display two strings
#include <stdio.h>
#include <conio.h>
void main()
{
#include <stdio.h>
#include <conio.h>
M09_ITL-ESL4791_02_SE_C09.indd 206 12/22/2012 5:04:03 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset