fork download
  1. #include <stdio.h>
  2.  
  3. #define SENTINEL -1
  4.  
  5. void foo(int *a) {
  6. size_t n = 0;
  7. while (*a != SENTINEL) {
  8. a++;
  9. n++;
  10. }
  11. printf("%zu elements.\n", n);
  12. }
  13.  
  14. int main(void) {
  15. foo((int[]){4, 5, 6, 7, 8, SENTINEL});
  16. foo((int[]){-1, -2, SENTINEL});
  17. foo((int[]){1, 2, 3}); // no sentinel -- UB!!
  18. }
  19.  
Success #stdin #stdout 0.01s 5512KB
stdin
Standard input is empty
stdout
5 elements.
0 elements.
8 elements.