What is difference between the following two function definitions?
A 2D array is being passed as parameter.
void fun(int a[][3])
{
//do some task
}
void fun(int (*a)[3])
{
//do some task
}
Nothing, []
is just syntactic sugar for a pointer.
Here's a simple test case to show that there's not even a difference in indexing:
#include <stdio.h>
void fun1(int a[][3]) { printf("%d\n", a[2][2]); }
void fun2(int (*a)[3]){ printf("%d\n", a[2][2]); }
void main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
fun1(a); // prints 9
fun2(a); // prints 9
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With