The remove function in C/C++ can be used to delete a file. The function returns 0 if files is deleted successfully, other returns a non-zero value.
Using remove() function in C, we can write a program which can destroy itself after it is compiled and executed.
Explanation: This can be done using the remove function in C. Note that, this is done in Linux environment. So, the remove function is fed the first parameter in command line argument i.e. a.out file (executable file) created after compiling . Hence the program will be destroyed.
By the time you will compile me I will be destroyed
After the output shown above, the a.out file will be removed.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- C Program to merge contents of two files into a third file
- Multithreading in C
- lseek() in C/C++ to read the alternate nth byte and write it in another file
- Self Destructing Code in C
- ftell() in C with example
- Program to Find the Largest Number using Ternary Operator
- Passing Reference to a Pointer in C++
- How to avoid Structure Padding in C?
- wcrtomb() function in C/C++
- vswprintf() function in C/C++