Pointers Questions and Answers
Practice ModeShowing 10 of 217 questions
Q101
int *const size = 10;
If the address of size is 3024, then size ++ is
Answer: Option D
Q102
int *ptr = (int *) malloc (sizeof (int));
ptr +=3;
If ptr points tot the memory location 1000 and after execution of the statement ptr+=3, ptr with point to the memory location ________ (Assume 32 bits for int).
Answer: Option D
Q103
The amount of memory to be allocated for the following array of pointers.
short *p[4];
Answer: Option D
Q104
int x = 1;
int *ptr = malloc (sizeof (int));
ptr = &x;
x=2;
*ptr=3;
Is there anything wrong with the above code ?
Answer: Option C
Q105
int x = 1;
int *ptr = malloc (sizeof (int));
ptr = &x;
x = 2;
*ptr = 3;
Is there anything wrong with the above code ?
Answer: Option C
Q106
int *ptr = malloc (5 * size of (int));
realloc (ptr, 10*size of (int));
for (i=0; i <10; i++) { ptr [i] = 0;}
Assuming realloc succeeds, what effect will the above sample have on the rest of the program ?
Answer: Option D
Q107
int *array [3];
int (*ptr) [ ] = array;
int x = 2, y = 3, z = 4;
Referring to the sample code above, how would you assign the second pointer in the array 'ptr' to point to the value of y?
Answer: Option A
Q108
void *ptr;
What would be the correct way to cast ptr in the code above to be a pointer to a 3 element array of function pointers with a return value of int and a single parameter of a pointer to char ?
Answer: Option D
Q109
100 main ( )
{
int count = 0;
int matrix [5 ] [5];
register int *ptr;
int i, j;
for (i=0, i<5;i++)
for (j=0; j<5; j++) matrix [i] [j] = count ++;
ptr = &matrix [1] [1];
printf ("%d\n", ptr [2]);
}
Referring to the sample above, what will be the value of "ptr[2]", after execution?
Answer: Option C
Q110
main ( )
{
int a[4] [2];
int b = 0, x; _
int i, y;
for (i=0; i<4; i++)
for (y=0; y<2;y++)
a [i] [y] =b++;
x = * (*(a+2) - 1);
}
What is the value of x in the above sample ?
Answer: Option B