693 views
6 votes
6 votes

Consider the following C code fragment (… denote further statements):

int main()
{
    int my_array[30][40][50];
    init_array(&my_array);
    ...
}


Which of the following is a valid declaration for the function init_array? Mark all the correct options.

  1.  
    void init_array(int ** array[30][40][50]);
  2.  
    void init_array(int (* array)[30][40][50]);
  3.  
    void init_array(int *** array);
  4.  
    void init_array(int ** array[30][40]);

 

3 Answers

Best answer
6 votes
6 votes
The argument being passed is a pointer to a 3-dimensional array of integers. So, only option B matches.
selected by
2 votes
2 votes

Answer : Option B

As address of whole 3D array is being passed in calling function. In declaration we should have some pointer which accepts 3D array address. So, let’s go through all options : 

Option A : False, int ** array[30][40][50] this means it is a array of [30][40][50] integer double pointer. but here were are not accepting pointer, we are accepting address and for that single pointer should be there.

Option B : As previous stated we want to accept address through single pointer and in option B it is given so correct.

Option C : Same reasoning as option A, we want to accept address of whole 3D array not some pointer. Option c would be true if some double pointer is passed by calling function. 

Option D : Same reasoning as option A. 

edited by
0 votes
0 votes

See ,here what are we passing to the function , address of arr right!!! means the pointer pointing to the whole 3D array, So , i think option B is the correct answer

  1. void init_array(int (* array)[30][40][50]); translates to this ->>>> array is a pointer to 3D array of int.
Answer:

Related questions

4 votes
4 votes
1 answer
1
9 votes
9 votes
1 answer
3
gatecse asked Jul 26, 2020
640 views
What will be the output of the following C program:#include<stdio.h int main() { char* disease = "COVID-19"; (*disease)++; printf("%s",disease); }DPWJE-$20$DOVID-$19$COVI...