A virtual machine is an emulation layer between a program and the OS that presents to the application a specialized environment to run in, than the raw environment that the OS provides.
This helps in many ways. For example, the applications become more portable. Another advantage is that a VM can implement things not available in the native OS. One more very important benefit is that the memory management is automatic and the application developers don't need to concern themselves with it -- which makes programs less susceptible to a host of known problems when the memory is managed manually in C/C++ programs. VMs are commonly implemented in C or C++.