RicardasSim icon

num of array elem

RicardasSim | PRO | 10/25/19 06:06:25 PM UTC | 0 ⭐ | 635 👁️ | Never ⏰ | []
C |

600 B

|

None

|

0 👍

/

0 👎

#include <stdio.h>
#include <stdlib.h>
 
int main()
{
 
    const char *testArr1[] = {"one","two"};
    const char *testArr2[] = {"one"};
    const char *testArr3[] = {0};
 
    unsigned int num;
 
    num = sizeof testArr1 / sizeof *testArr1;
 
    printf("testArr1: %d\n", num);
 
    num = sizeof testArr2 / sizeof *testArr2;
 
    printf("testArr2: %d\n", num);
 
    num = sizeof testArr3 / sizeof *testArr3;
 
    printf("testArr3: %d\n", num);
 
    if( num==1 && testArr3[0] == NULL) printf("null\n");
 
    return 0;
}
 
/*
output:
 
testArr1: 2
testArr2: 1
testArr3: 1
null
 
*/

Comments