fueanta

Passing implicitly sized array.

Oct 5th, 2016
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "cstdio"
  2.  
  3. void print_arr(int arr[]);
  4.  
  5. int main() {
  6.  
  7.     int arr[] = {1,2,3,4,5,6,7};
  8.     print_arr(arr);
  9.  
  10.     printf("\n\n%lu", sizeof(arr)/sizeof(int));
  11.     return 0;
  12.  
  13. }
  14.  
  15.  
  16. void print_arr(int *arr) {
  17.  
  18. for (int i= 0; *(arr+i) != NULL; i++) {
  19.     printf("%d ", *(arr+i));
  20. }
  21.  
  22. printf("\n\n%lu", sizeof(arr)/sizeof(int));
  23.  
  24. }
RAW Paste Data