Questions 2 and 3 of Pointers MCQ

For Q- 2: I am not able to understand what options B and C are trying to state. Could you please explain why C is the correct answer?

For Q-3: How does new actually work in this case? Are we trying to create an array of pointers that each point to an integer array of size 100?

Hello @IronVenom,

Ques 2:
A. Option A is wrong, because we cannot perform pointers asthmatics with void pointers.
D. So, option D is also incorrect.

B. A void pointer is a pointer that has no associated data type with it. A void pointer can hold address of any type and can be typcasted to any type.

nt a = 10;
char b = ‘x’;

void *p = &a; // void pointer holds address of int ‘a’
p = &b; // void pointer holds address of char ‘b’.
We cannot use it directly.
You are required to refer them to an object of some type before using them like:
void *p = &a;
Thus, this option is also wrong.

C. A c pointer knows the types of pointers and indirectly referenced data items at runtime.
We have already discussed that a must have a type before using it. So, it knows the type of data it can point to.
Also, the *p (referenced data item i.e. the value stored at the location pointed by it) is accessed at the time of execution or at the time , when we are using it.

Ques 3:
The option B must be correct:
int **arr=new int *[100];

Here, new keyword is used for dynamic memory allocation.
c) option will create a pointer to integer array of length 100.
b) will create a pointer to arrays of pointer of integer type, with size 100.
int **arr; It is the pointer to pointer
int **arr= new int *[100]; it is required dynamic arrays of pointer.

Hope, this would help.
Give a like, if you are satisfied.

Hello @IronVenom,

I read the question incorrectly.
I have modified my reply, you can check the correct answer.

Hope, this would help.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.