0
void function(int *,int, int);

here the function prototype is declared.

function((int *)s,3,2);

here calling a function where a 2 D array is passed into this function arrays is denote by s and the 3 and 2 are row and column respectively. so what does mean of this (int *)s. for example &d means the address of variable d. *p means it is a pointer that contains the address of a variable and * means the value at that address, so how to explain this (int *)s.

Elikill58
  • 3,190
  • 22
  • 17
  • 38
  • It is a *casting*: convert the value of `s` to `int *`. – MikeCAT Jun 23 '21 at 14:08
  • If `s` is a 2-d array, its type is `int[][]`, which degrades to `int[]*` when passed to a function. That call casts it to `int*`. – Barmar Jun 23 '21 at 14:09
  • @Barmar The type of a "2d" array must have a size for its second dimension, and then it decays to `int (*)[SOME_SIZE]`. – Some programmer dude Jun 23 '21 at 14:10
  • Not answering your question, but are you sure that arguments 2 and 3 are row and column? Isn't it number of rows and number of columns? – fpiette Jun 23 '21 at 14:11
  • @Someprogrammerdude I was leaving out the sizes since I didn't know them, but you're right that I got the order. – Barmar Jun 23 '21 at 14:12
  • 2
    In case `s` is a 2D array then `(int *)` is _code smell_. What's the declaration of `s` and how does the function use it? – Lundin Jun 23 '21 at 14:26
  • @fpiette yes 2 and 3 are the number if rows and columns. – Sumit Baloda Jun 24 '21 at 03:10
  • @SumitBaloda Then please [edit](https://stackoverflow.com/review/suggested-edits/29257169) your question to clearly state that. When you simply say in comment, other reader will be forced to read everything to realize what you ask. – fpiette Jun 24 '21 at 06:14
  • It usually means that the authors don't care about undefined behaviour in their code. – n. 1.8e9-where's-my-share m. Jun 24 '21 at 06:31
  • Does this answer your question? [Do I cast the result of malloc?](https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc) – Sekomer Jun 24 '21 at 08:01

0 Answers0