in Programming edited by
243 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);
in Programming edited by
243 views

2 Comments

typo in options: ‘voin’
1
1
Fixed.
1
1

1 Answer

4 votes
4 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

4 Comments

in the question, what does this mean “valid syntax to pass OneD and TwoD”?
does it mean we need a function that could handle both of these types of arrays as parameter?
0
0

@Shubhamishere not both it should accept one of the given array as parameter.

1
1

while passing 2D array to the function we have to mention number of rows each column have.

I did not understand this line. Is there a typo? Because we are mentioning no. of columns here in these options A,B,C

1
1

@Shubhamishere yes thanks for pointing out :)

0
0
Answer:

Related questions