Explaination needed for this code. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 6

Explaination needed for this code.

This is a code made by @harshit. But when some changes are done. I am not understanding why the answer is this. Could anyone explain. I have linked the code too. https://code.sololearn.com/clYC8LLBLEFq/#cpp

25th Jan 2018, 1:50 PM
Akash Pal
Akash Pal - avatar
2 ответов
+ 9
Character pointers are special because they are treated as C-style strings by std::cout. It doesn't output the address stored by p in this case, it outputs the string starting from the first character it is pointing to. Whatever you are seeing in the output followed by 'b' are garbage values left behind in the memory addresses following the address of variable b.
25th Jan 2018, 4:09 PM
Hatsy Rei
Hatsy Rei - avatar
+ 6
Thanks for explaining @Cool.
25th Jan 2018, 2:16 PM
Akash Pal
Akash Pal - avatar