0
C program sizeof
# include <stdio.h> void print(int *arr) { int n = sizeof(arr)/sizeof(arr[0]); printf ("%d\n ", sizeof(arr)); printf ("%d\n\r ", sizeof(arr[0])); //printf ("%d ", n); int i; for (i = 0; i < n; i++) printf("%d ", arr[i]); } int main() { int arr[] = {1, 2, 3, 4, 5, 6, 7, 8}; printf ("%d\n ", sizeof(arr)); printf ("%d\n\r ", sizeof(arr[0])); print(arr); return 0; }
2 ответов
+ 2
Line 5 contains a mistake: when you pass an array you don't pass it's size, so sizeof(arr) will be the size of the pointer type (32 or 64 bits), not of the whole array.
- 2
i need explanation about output of this program