How do languages without garbage collection such as C?
At some level, they dont. C is at that level. In C, you, the programmer, are responsible for memory management. Get it wrong and your program has undefined behavior, which means just about anything can happen. Your program can work or it cannot or it can work sometimes and other times it wont and you may have no way to predict which is which. C++ has tried to remedy that problem. C++ has several layers of features that attempt to make memory management easier for the programmer to do. Constructors allow one to make certain that when an object is created, that you have initialized all the important members (fields) to consistent values, and that when you copy objects or assign them, you do so in a consistent fashion. Private and protected access attempt to keep your members from being changed out from under you without your consent. Container classes give you ways of grouping things where the container takes care of memory management for you. Iterators give you pointers that arent associated with memory management and can be scoped to only refer to objects that actually exist. References are pointers that can only point to actual objects and never be NULL. The RAII (resource allocation is initialization) takes the constructor model farther. Smart pointers are another way of getting storage that the compiler manages for you. (Rusts borrow checkers takes this even a step further). The programmer still has to manage memory themselves, but they have lots of tools that allow them to express how they want memory to be managed and the compiler will help enforce and implement.