You're misunderstanding virtual memory. Programs and the operating system always operate in virtual memory. If you malloc 10 bytes, or 10 million, or 10 billion, you are allocating virtual memory. Your code, your stack space (automatic storage, alloca, etc.), your global storage (if you have any), also all live in virtual memory. If you take the address of something, as in
&myVariable, the result is a virtual address. You are ''never'' using physical memory addresses under a virtual memory OS.
The sum total of virtual address space needed by the OS plus all the programs you have running will routinely exceed the size of RAM, even on today's systems. This can even be true for a single program. So, RAM usage + "swap space" for a single process can easily exceed RAM.
Heck, the whole point of virtual memory - well, one of the important points - is to allow you to write code that needs more "memory" (whether for code, data, whatever) than you have RAM.
As others said in comments, it is up to the operating system to decide what portion of the total virtual address space (for the OS + all processes) is kept in RAM and which is out on disk (in "swap" space). If you reference some page (generally 4 Kbytes on x86/x64 systems) of your virtual address space that isn't in RAM, the OS "swaps it in" for you (we also say "pages it in" or "faults it in", as this is stimulated by a "page fault"). Sometime later the OS may decide it's short on RAM and may remove some of the oldest-referenced or least-often-referenced stuff from RAM. If that stuff was modified since it was last brought into RAM, the modified version has to be saved on disk - that's why stuff gets put in "swap space" (or in Windows terms, the pagefile).
By the way, the pagefile/swapfile/swap space is by far not the only place where virtual memory contents are held if they're not in RAM. Mapped files, which generally include every code file, are another place. Code is rarely modified while in RAM so it generally only swapped in. If it must be lost from RAM it's just dropped and if needed again can be swapped back in from the same file it came from originally.