Objective Type Questions on Pointers
Posted by
Ravi Kumar at Sunday, September 25, 2011
Share this post:
|
1.What would be the output of the following program?
#include "stdio.h"
main( )
{
printf( "%d %d", sizeof(NULL),sizeof(" " ) );
}
(a) 1 1
(b) 1 2
(c) 2 1
(d) 2 2
Ans: c
2.How many bytes are occupied by near,far and huge
pointers?
(a) 2,2,4
(b) 2,4,4
(c) 2,4,2
(d) 2,2,2
Ans: b
4.Can anything else generate a Null Pointer Assignment
error?
(a) Yes
(b) No
(c) Can't say
(d) None
Ans: a
5. Are the three declarations char **apple, char
*orange[ ], and char cherry [ ] [ ] same?
(a) Yes
(b) No
(c) Can't say
(d) None
Ans: b
6.Can two different near pointers contain two different
addresses but refer to the same location in memory?
(a) Yes
(b) No
(c) Can't say
(d) None
Ans: b
7. Can two different far pointers contain two different
addresses but refer to the same location in memory?
(a) Yes
(b) No
(c) Can't say
(d) None
Ans: a
8. Can two different huge pointers contain two different
addresses but refer to the same location in memory?
(a) Yes
(b) No
(c) Can't say
(d) None
Ans: b
9.Would the following program give any warning on compilation?
#include "stdio.h"
main( )
{
int *p1,i=25;
void *p2;
p1=&i;
p2=&i;
p1=p2;
p2=p1;
}
(a) Yes
(b) No
(c) Can't say
(d) None
Ans: b
10.Would the following program give any warning on compilation?
#include "stdioh"
main( )
{
float *p1,i=25.50;
char *p2;
p1=&i;
p2=&i;
}
(a) Yes. Suspicious pointer conversion in function main
(b) No
(c) Can't say
(d) None
Ans: a
11.What warning would be generated on compiling the following
program?
main( )
{
char far *scr;
scr=0*B8000000;
*scr = 'A';
}
(a) Suspicious pointer conversion in function main
(b) Non-portable pointer assignment in function main
(c) Can't say
(d) None
Ans: b
12.How would you eliminate the warning generated on compiling
the following program?
main( )
{
char far *scr;
scr=0*B8000000;
*scr = 'A';
}
(a) Use the typecast scr= (char *far ) 0*B8000000;
(b) Use the typecast scr= (char far * ) 0*B8000000;
(c) Use the typecast scr= (char **far ) 0*B8000000;
(d) Use the typecast scr= (char far ** ) 0*B8000000;
Ans: b
13. In a large data model (compact, large, huge) all pointers
to data are 32 bits long,whereas in a small data model (tiny,
small,medium) all pointers are 16 bits long
(a) True
(b) False
(c) Can't say
(d) None
Ans: a
14. A near pointer uses the contents of CS register
(if the pointer is pointing to code) or contents of DS
register (if the pointer is pointing to data) for the
segment part,whereas the offset part is stored in the
16-bit near pointer
(a) True
(b) False
(c) Can't say
(d) None
Ans: a
15. What would be the output of the following program?
main( )
{
char far *a=0*00000120;
char far *b=0*00100020;
char far *c=0*00120000;
if(a==b)
printf("\nHello");
if(a==c)
printf("\nHi");
if(b==c)
printf("\nHello Hi");
if(a>b && a>c &&b>c)
printf("\nBye");
}
(a) Hello
(b) Hi
(c) Hello Hi
(d) Bye
Ans: d
16. What would be the output of the following program?
main( )
{
char huge *a=0*00000120;
char huge *b=0*00100020;
char huge *c=0*00120000;
if(a==b)
printf("\nHello");
if(a==c)
printf("\nHi");
if(b==c)
printf("\nHello Hi");
if(a>b && a>c &&b>c)
printf("\nBye");
}
(a) Hello
(b) Hi
(c) Hello Hi
(d) all
ans: d
17. Are the expressions *ptr++ and ++*ptr same?
(a) Yes
(b) No
(c) Can't Say
(d) None
Ans: b
18.Can you write another expression which does the same
job as ++*ptr?
(a) (ptr*)++
(b) *ptr++
(c) ptr*++
(d) (*ptr)++
Ans: d
19. What would be the equivalent pointer expression for
referring the same element as a[i][j][k][l]?
(a) *(*(*(*(a+i)+j)+k)+l)
(b) *(*(*(*a[i])[j])[k])[l])
(c) both
(d) None
Ans: a
20. What would be the output of the following program ?
main( )
{
int arr[ ]={12,13,14,15,16};
printf("\n%d %d %d",sizeof(arr),sizeof(*arr),
sizeof(arr[0]));
}
(a) 10 4 4
(b) 10 4 2
(c) 10 2 2
(d) 10 2 4
Ans: c
21.What would be the output of the following program
assuming that the array begins at location 1002?
main( )
{
int a[3][4]={1,2,3,4,
5,6,7,8,
9,10,11,12
};
printf( "\n%u %u %u",a[0]+1,*(a[0]+1),*(*(a+0)+1));
}
(a) 1004 2 2
(b) 1004 4 4
(c) 1002 2 2
(d) 1002 4 4
Ans: a
22. What would be the output of the following program
assuming that the array begins at location 1002?
main( )
{
int a[2][3][4]={ {
1,2,3,4,
5,6,7,8,
9,1,1,2
},
{
2,1,4,7,
6,7,8,9,
0,0,0,0
}
};
printf("\n%u %u %u %d",a,*a,**a,***a);
}
(a) 1002 1002 1002 2
(b) 1002 1002 1002 1
(c) 1004 1004 1004 1
(d) 1004 1004 1004 2
Ans: b
23. In the following program how would you print 50
using p?
main( )
{
int a[ ]={10,20,30,40,50};
char *p;
p = (char *) a;
}
(a) printf("\n%d",*( (int *)p+4) );
(b) printf("\n%d",( (int *)p+4) );
(c) printf("\n%d",*( (int )p+4) );
(d) printf("\n%d",*( (int **)p+4) );
Ans: a
24.In the following program add a statement in the
function fun( ) such that address
of a gets stored
in j
main( )
{
int *j;
void fun(int **);
fun(&j);
}
void fun(int **k)
{
int a=10;
}
(a) *k=&a;
(b) &a=*k;
(c) &k=*a;
(d) *a=&k;
Ans: a
25.How would you declare an array of three function
pointers where each function receives two ints and
returns a float?
(a) float (arr[3])(int,int);
(b) int (arr[3])(float,float);
(c) int (*arr[3])(float,float);
(d) float(*arr[3])(int,int);
Ans: d