C program sizeof | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; }

27th Mar 2019, 4:36 AM
DESIGN & DEVELOPMENT
DESIGN & DEVELOPMENT - avatar
2 Answers
+ 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.
27th Mar 2019, 4:41 AM
Vlad Serbu
Vlad Serbu - avatar
- 2
i need explanation about output of this program
27th Mar 2019, 4:37 AM
DESIGN & DEVELOPMENT
DESIGN & DEVELOPMENT - avatar