Basic C++ “Virus”

March 25, 2017 | Views: 24533

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here

Hi everyone,

This is my first article on this site, I hope you will enjoy it! 🙂

What I’m going to show you today is a simple C++ virus, or scam (whatever you want to call it), that is very annoying once opened and requires a system reboot in order to stop it.

What it actually does is very simple to understand:

  • It basically goes in an infinite loop, running only one command that makes the computer to continuously produce a very annoying sound, and because of that infinite loop, the program cannot be closed.

Without further introduction, here is the code:

#include <iostream>

using namespace std;

int main() {

for(long long i=1;i<=100;i--)



// very important, when saving this program, save it with this extension: ".cpp" and after getting its executable, you can troll whoever you want XD

//notice that we started a loop with i=1 and set it to stop when i reaches 100, the only problem being that "i--", that creates the infinite loop


Thank you for reading my article. I hope you enjoyed it!

Best regards!

Share with Friends
Use Cybytes and
Tip the Author!
Share with Friends
Ready to share your knowledge and expertise?
  1. This reply is written with no intention to offend, but in my opinion this does not really fall under the category of malware or a virus. Infinite loops are quite common mistakes made by beginner programmers and are considered as programming bugs or errors if not mistaken. I would also add that some situations merit the use of infinite loops in programs and are used by programmers with a intended purpose. A quick and easy way to write an infinite loop is: for(;;) {}

    If this was executed it would become more annoying than malicious. It would have to be formulated with some other code or plan of action to be considered malicious. the most it would probably do on the multi tasking CPUs of today would at the most part is cause a freezing of the system that could be easily killed by opening the task manager and stopping the execution of the program or by opening a terminal and running some basic kill commands depending the OS you are using. this kind of error/bug reaction happens all the time with poorly written programs and has numerous remedies. My assessment of this code could be wrong because I am not a programmer per say, but this is just my opinion on this code in how it is presented and the possible outcome if executed as is. I would also add if intention is to inject in someone else’s code, more than likely there would be a built in break written in the code because of the commonality of making an infinite loop mistake in coding. You could also try typing Ctrl + Pause/Break on your keyboard to break out of a program continuously looping.

  2. Do I have to copy paste in notepads with .bat extension
    Plz tell

    • no, you need to first download either “dev-cpp” of “code blocks”.
      Then open a file in one of those programs and copy-paste this.
      save it as a c++ code (“.cpp”)
      then build+run it to test it, or take the “.exe” that will be created and make a prank to a friend.

      P.S. don’t forget that this is totally harmless to your system. it is for entertainment purposes only.

    • Batch version of the same is

      %0 | %0

  3. a more simple loop could be there it may become more handy !!! anyways well done .

  4. Interesting, that single line with i– could come in handy when trying to debug someone elses code, or possibly even help when analyzing malware.

  5. Funny, lol Thanks for this. +5

Page 1 of 3123»
Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Support Cybrary

Donate Here to Get This Month's Donor Badge


We recommend always using caution when following any link

Are you sure you want to continue?