C-Pointers Question and Answer

C-Pointers Question and Answer
101. int *const size = 10;
If the address of size is 3024, then size ++ is
  • 11
  • 3025
  • 3026
  • invalid
Show Answer
102. 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).
  • 1006
  • 1003
  • 1010
  • none
Show Answer
103. The amount of memory to be allocated for the following array of pointers.
short *p[4];
  • no memory
  • 4 bytes
  • 6 bytes
  • 16 bytes
Show Answer
104. int x = 1;
int *ptr = malloc (sizeof (int));
ptr = &x;
x=2;
*ptr=3;
Is there anything wrong with the above code ?
  • No, x will be set to 2.
  • No, x will be set to 3.
  • Yes, there will be a memory overwrite.
  • yes, there will be a memory lead.
Show Answer
105. int x = 1;
int *ptr = malloc (sizeof (int));
ptr = &x;
x = 2;
*ptr = 3;
Is there anything wrong with the above code ?
  • No, x will be set to 2.
  • No, x will be set to 3.
  • Yes, there will be a memory overwrite.
  • Yes, There will be a memory leak.
Show Answer
106. 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 ?
  • The pointer "ptr" will contain an array of 10 that is initialized to 0 with no issues.
  • This will result in a memory overwrite but no memory leak.
  • This will result in a memory leak but no memory overwrite
  • This will result in both a memory leak and memory overwrite.
Show Answer
107. 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?
  • (*ptr) [1] = y;
  • (*ptr) [2] = &y;
  • *ptr [2] = y;
  • (*ptr) [1] =&y;
Show Answer
108. 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 ?
  • (int ((*)[3] (char*)ptr
  • ((int*) (*[3] (char))ptr
  • (int (*(*)[3])(char*)ptr
  • (int *(*)[3](char *))ptr
Show Answer
109. 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?
  • 6
  • 7
  • 8
  • 9
Show Answer
110. 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 ?
  • 2
  • 3
  • 4
  • 5
Show Answer
Questions and Answers for Competitive Exams Various Entrance Test