In netCDF-4 files it's possible to create a data type which corresponds to a C struct. These are known as “compound” types (following HDF5 nomenclature).
That is, a netCDF compound type is a data structure which contains an arbitrary collection of other data types, including other compound types.
To define a new compound type, use nc_def_compound. Then call nc_insert_compound for each type within the compound type.
Read and write arrays of compound data with the nc_get_vara and nc_put_vara functions. These functions were actually part of the netCDF-2 API, brought out of semi-retirement to handle user-defined types in netCDF-4.