edited by
684 views
3 votes
3 votes

Let arrays OneD and TwoD are declared as follows as:

int OneD[10];
int TwoD[4][5];

Which of the following is/are valid syntax to pass OneD and TwoD to some function fun()?

A syntax is valid if it gets compiled without any warning or error.

  1. void fun(int OneD[10]);
  2. void fun(int OneD[5]);
  3. void fun(int TwoD[][5]);
  4. void fun(int **TwoD);
edited by

1 Answer

6 votes
6 votes

Answer: A,B,C

Option A, B is correct it doesn’t matter what size you mention because what is being passed is the pointer pointing to the initial address of the array.

(Source: C Programming Language by Dennis Ritchie)

 

Option C is correct, option D is wrong because while passing 2D array to the function we have to mention number of columns each row have.

Internally compiler will treat it as 

void fun(int (*TwoD)[5]);

(Source: C Programming Language by Dennis Ritchie)

edited by
Answer:

Related questions

1 votes
1 votes
2 answers
1
GO Classes asked Aug 6, 2022
1,117 views
In which of the following case(s) character array must end with null char?char c[] = "GATE";char c[] = {'2', '0', '2', '3'};char c[4] = "GATE";char c[16] = "2023";