Computers are usually infected with a virus when a user unknowingly installs it via a downloaded file.
A virus, specifically a computer virus, is a piece of malicious software that infiltrates a user's computer without the user’s awareness. The virus can then execute a range of malicious operations on the host computer.
The term was formally coined by Fred Cohen in 1983 as a metaphor for the way in which a computer virus mimics the diffusion of an infectious virus between humans.
Computers are usually infected with a virus when a user unknowingly installs it via a downloaded file. The virus attaches itself to another program in such a way that the execution of the host program can trigger the operations of the virus at the same time. It can also self-replicate, and insert itself onto other programs or files.
Keep in mind that each and every computer virus out there is designed differently. Most of them perform actions that are malicious, such as destroying data, whilst some can stay idle until a particular computer operation prompts their code to run.
Viruses can also spread when the software or documents that they are attached to are transferred from one computer to another using a network, USB stick, hard drive, or other form of data transfer.
There are also viruses that implement stealth strategies to avoid their detection by anti-virus software, especially if the software is outdated. Some viruses have the ability to infect files without thereby increasing their size; others can avoid detection by simply killing the task (in the task manager) that runs the antivirus software.