Hacker News new | ask | show | jobs
by satysin 3527 days ago

    char *p;
p doesn't point to anything[0]. You have declared a pointer to char but not given it any memory to point to. It is uninitialised.

    *p = 'c';
So what are you dereferencing here? You can't dereference something you haven't initialised.

[0] well it might point to something, it is up to the compiler as it is UB.

Edit: btw if you could not answer this very simple problem please do not advertise yourself as a C programmer as you are not yet. Learn C and then advertise yourself as a C programmer.

1 comments

Yeah, one more thing. C and C++ type languages where you have to manage memory allocation are a different kind of intellectual challenge than languages like java or python. It takes a certain amount of try and failure and intellectual carefulness to get the ability to write trustworthy code. Just keep going at it. And be careful not to call yourself an expert c programmer, even after you get basic fluency. That's usually a sign that someone is not a great programmer in my experience :-)