When your program ends, all the memory it used (whether dynamically allocated or not) is returned to the operating system. It doesn't matter if it's a C program, a C++ program, a C# program, or any other kind of program you might be writing.
Now, just because the OS will reclaim the memory doesn't mean you can be cavalier about memory management. While your program runs, you should try to take care of freeing any memory you're done with. Not doing so will cause "memory leaks", and those can certainly affect your program and the system it's running on, at least while your program is running.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…