Pointers Questions and Answers

Practice Mode
Showing 10 of 217 questions
Q101
int *const size = 10; If the address of size is 3024, then size ++ is
  • A 11
  • B 3025
  • C 3026
  • D invalid
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).
  • A 1006
  • B 1003
  • C 1010
  • D none
Answer: Option D
Q103
The amount of memory to be allocated for the following array of pointers. short *p[4];
  • A no memory
  • B 4 bytes
  • C 6 bytes
  • D 16 bytes
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 ?
  • A No, x will be set to 2.
  • B No, x will be set to 3.
  • C Yes, there will be a memory overwrite.
  • D yes, there will be a memory lead.
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 ?
  • A No, x will be set to 2.
  • B No, x will be set to 3.
  • C Yes, there will be a memory overwrite.
  • D Yes, There will be a memory leak.
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 ?
  • A The pointer "ptr" will contain an array of 10 that is initialized to 0 with no issues.
  • B This will result in a memory overwrite but no memory leak.
  • C This will result in a memory leak but no memory overwrite
  • D This will result in both a memory leak and memory overwrite.
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?
  • A (*ptr) [1] = y;
  • B (*ptr) [2] = &y;
  • C *ptr [2] = y;
  • D (*ptr) [1] =&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 ?
  • A (int ((*)[3] (char*)ptr
  • B ((int*) (*[3] (char))ptr
  • C (int (*(*)[3])(char*)ptr
  • D (int *(*)[3](char *))ptr
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?
  • A 6
  • B 7
  • C 8
  • D 9
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 ?
  • A 2
  • B 3
  • C 4
  • D 5
Answer: Option B
Questions and Answers for Competitive Exams Various Entrance Test