0
#include <stdio.h>

void array_print (int *A)
    {

        int count = sizeof(A);

        for (size_t i = 0; i < count; i++)
        {
            printf("%d",A[i]);
         }

     }

 int main(int argc, char const *argv[])
 {
     
     int arr[] = {1,2,3,4,5};
     
     array_print(are);

     return 0;
 }
gsmnit
  • 1
  • 1
  • I don't think so. – MikeCAT Mar 15 '21 at 18:06
  • No. After an array-to-pointer-decay you only have the pointer without any knowledge about the size. So in your case you need to pass the address and the size to `array_print`. – Werner Henze Mar 15 '21 at 18:08
  • A pointer value is the address of a single object - there's no metadata in the pointer to indicate whether it's pointing to the first of sequence of objects or not, nor how many objects would be in that sequence. Array sizes must be tracked separately, or the array must contain a sentinel value of some kind. – John Bode Mar 15 '21 at 18:23

0 Answers0