fork download
  1. #include <stdio.h>
  2.  
  3. #define IU_ARRAY_SIZE(array) ((int)(sizeof(array) / sizeof((array)[0])))
  4.  
  5. int find(int xs[], int x) {
  6. int n = IU_ARRAY_SIZE(xs), i = 0;
  7. printf("Inferred N = %d\n", n);
  8. while (i < n) {
  9. if (xs[i] == x) return i;
  10. ++i;
  11. }
  12. return -1;
  13. }
  14.  
  15. int main(void) {
  16. int items[] = {1, 2, 3, 4};
  17. printf("Initial N = %d\n", IU_ARRAY_SIZE(items));
  18. printf("2 is at %d\n", find(items, 2));
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
Initial N = 4
Inferred N = 1
2 is at -1