RicardasSim

num of array elem

Oct 25th, 2019
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.  
  7.     const char *testArr1[] = {"one","two"};
  8.     const char *testArr2[] = {"one"};
  9.     const char *testArr3[] = {0};
  10.  
  11.     unsigned int num;
  12.  
  13.     num = sizeof testArr1 / sizeof *testArr1;
  14.  
  15.     printf("testArr1: %d\n", num);
  16.  
  17.     num = sizeof testArr2 / sizeof *testArr2;
  18.  
  19.     printf("testArr2: %d\n", num);
  20.  
  21.     num = sizeof testArr3 / sizeof *testArr3;
  22.  
  23.     printf("testArr3: %d\n", num);
  24.  
  25.     if( num==1 && testArr3[0] == NULL) printf("null\n");
  26.  
  27.     return 0;
  28. }
  29.  
  30. /*
  31. output:
  32.  
  33. testArr1: 2
  34. testArr2: 1
  35. testArr3: 1
  36. null
  37.  
  38. */
Advertisement
Add Comment
Please, Sign In to add comment