can i do some calculation using the sizeof operator in c to get
the rows count inside a function who receives as a parameter only
a two dimensional array without any information about rows or columns count in this passed array?
void main(void){
int A[5][6];
int columnsC = sizeof(A[0]) / sizeof(int);
int rowsC = ( sizeof(A)/sizeof(int) ) / columnsC;
printf("rows: %d\ncolumns: %d\n", rowsC, columnsC);
getch();
}
the previous code worked for me, but i can’t find a helpful resource to know how to apply this on a function of the following header:
void fun(int arr[][10])
i”m studying a course on Programming Languages Principles, and some times think of things differently and look for learning resources, and this helps a lot, but not this time apparently.
i admire any help.
No. There’s no way find the size of an array when passed to a function. Array decays into a pointer when passed to a function.
This:
is actually syntatic sugar for:
Instead you can pass the size as a thrid argument or size as an element of the array itself.