Why is dangerous to run this?

May 23, 2013 at 9:54pm
I have an exam tomorrow and one of the question from the review is to explain it is dangerous to run a program with this part of the code and what could happen?


1
2
char *myPtr;
*(myPtr + 2) = '0';
May 23, 2013 at 10:07pm
myPtr has undefined value because it was not initialized or assigned. So the code

*(myPtr + 2) = '0';

has undefined behaviour. Where character '0' will be written?

May 23, 2013 at 10:32pm
Thanks
Topic archived. No new replies allowed.