I am writing C code that has some dynamic arrays/list that are represented with a struct that contains the number of elements and a pointer to the elements.I have some functions that are doing some similar work with that structs, for example printing the elements. To use the same code I decided to create a struct to that holes an abstract data type and the printing function receives a pointer to that struct.A specific struct looks like that:typedef struct {    int numOfElements;    int *element;} LIST_INT, *PLIST_INT; The generic struct look like that:typedef struct {    int numOfElements;    void *element;} LIST_GEN, *PLIST_GEN;Is that the right approach? This is the code example:#include <stdio.h>#include <stdlib.h>typedef struct {    int numOfElements;    char *element;} LIST_CHAR, *PLIST_CHAR;typedef struct {    int numOfElements;    int *element;} LIST_INT, *PLIST_INT;typedef struct {    int numOfElements;    void *element;} LIST_GEN, *PLIST_GEN;typedef void(*fpPrintElement)(void *element);void print_list(PLIST_GEN list, int elementSize, fpPrintElement printElement) {    int i = 0;    int num = list->numOfElements;    for (i = 0; i < num; ++i) {        printElement(((char *)(list->element) + i * elementSize));    }    return;}void print_int(int * element) {     printf(%d , *element);}void print_char(char * element) {    printf(%c , *element);}void main() {    LIST_INT list_int;    list_int.numOfElements = 10;    list_int.element = malloc(sizeof(list_int.element) * list_int.numOfElements);    for (int i = 0; i < list_int.numOfElements; ++i) {        list_int.element[i] = i * 1000;    }    LIST_INT list_char;    list_char.numOfElements = 7;    list_char.element = malloc(sizeof(list_char.element) * list_char.numOfElements);    for (int i = 0; i < list_char.numOfElements; ++i) {        list_char.element[i] = i + 35;    }    print_list((PLIST_GEN)&list_int, sizeof(*list_int.element), print_int);    print_list((PLIST_GEN)&list_char, sizeof(*list_char.element), print_char);    return;}
Struct with abstract type member in c
c