What happened to this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

What happened to this code?

I was very innocently creating a pointer in C++ and iterating. Then I get this very strange result. Why? https://code.sololearn.com/cRPckMPoqv0f/?ref=app

16th Feb 2019, 5:46 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
6 Answers
+ 12
Your for loop doesn't have a break condition so it just goes on and on and prints whatever is in the memory locations after *name. And no, C(++) doesn't stop you from doing that so it's your job as a programmer to prevent accessing the 10th, 100th or 1000th element of an array that has only 6 elements. If you don't, your program will likely just crash at some point or you risk data loss
16th Feb 2019, 6:07 AM
Anna
Anna - avatar
+ 4
Infinite loop? Weird...
16th Feb 2019, 5:50 AM
Tony
Tony - avatar
+ 4
When i remove the “++” after the “name” it works just fine. Also this is weird. I feel like the playground has a protection to prevent sensitive data from leaking out, can someone explain me what is the “LIFE_BARRIER”? Is what i understand correct?
16th Feb 2019, 11:38 AM
Nopparuj
Nopparuj - avatar
+ 2
Anthony Quick Like wouldn't it throw an error?
16th Feb 2019, 5:55 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
You might have to specify where does the string end https://code.sololearn.com/cFvYYLlENsif/?ref=app
17th Feb 2019, 7:30 AM
Infinity
Infinity - avatar
+ 1
i have one question , Can I learn complete java with sololearn ???
16th Feb 2019, 5:35 PM
Bhargab Hazarika
Bhargab Hazarika - avatar