Garbage collector in C++ is known as smart pointers.
I don't think it is possible with c language as it is using template and class to free memory. There are some libraries which provides C programs to garbage collection capabilities.
The BDW(The Boehm-Demers-Weiser GC) library is a freely available. The BDW collector comes as a static or dynamic library and is installed easily by downloading the corresponding package.