How to get size of array of structs in C

1 Answer

0 votes
#include <stdio.h>

typedef struct {
    int arr[5];
    char ch;
} ST;

int main(void) {

    static const ST s[] = { {{ 3, 5, 9 }, 'z'}, {{7}, 'a'}, {{ 4, 8 }, 'x'} };

    size_t struct_size = sizeof s / sizeof s[0];

    printf("%zu", struct_size);

    return 0;
}




/*
run:

3

*/

 



answered Apr 24, 2023 by avibootz

Related questions

1 answer 105 views
1 answer 170 views
2 answers 278 views
278 views asked May 8, 2019 by avibootz
1 answer 143 views
1 answer 162 views
...