Rotate image (square matrix) by 90 deg
Tue, 06 May 2025
The function myfunc below is suppposed to print the size of array passed to it as parameter(arr).
What do you think is the problem (if any)
void myfunc(int arr[], int n)
{
printf("Size of Array : %d", sizeof(arr));
}
int main()
{
int a[5] = {1, 2, 3, 4, 5};
myfunc(a, 5);
}
Solution:
The problem is that in C language, array parameters are passed as pointers. So the signature of function myfunc above is exactly same as
void myfunc(int *arr, int n)Since arr is a pointer (and not an array) pointing to the first element of the array a(on the activation record of main function).

printf("Size of Array : %d", sizeof(int)*n);
Tue, 06 May 2025
Tue, 06 May 2025
Tue, 06 May 2025
Leave a comment