Can this code really kill the memory? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can this code really kill the memory?

#include <iostream.h> void main() { char a=0; char *ptr=&a; while (1) { *ptr =0; ptr++; } }

3rd Nov 2019, 5:53 AM
Harshit Sharma
Harshit Sharma - avatar
2 Answers
+ 8
If there were no protections by the OS, yes. In reality however every modern OS stops programs that access memory that doesn't belong to them. Linux does this very strictly, Windows is a bit more tolerant but overall you can't really abuse pointers in that way.
3rd Nov 2019, 6:51 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
- 1
Let me see if I understand, you are creating an infinite loop?
3rd Nov 2019, 9:50 AM
Fernando Pozzetti
Fernando Pozzetti - avatar