You declare some pointer and give it whatever value 'c' is?
I probably would have gotten the question wrong too and just saying "Get out" is kind of harsh.
You declare some pointer and give it whatever value 'c' is?
I probably would have gotten the question wrong too and just saying "Get out" is kind of harsh.
If you can't do that, you don't understand pointers. If you don't understand pointers, you're going to write really buggy code.
I've never told someone to leave an interview early. That's a bit unprofessional in my view. But I certainly wouldn't hire a C programmer who doesn't understand pointers.
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.
Back to the question. In C or C++ the pointer is pointing to a memory location. If you don't set it to something (ie no malloc, or assignment, then it is uninitialized and you can't use what it points to. It is essentially a random number. Looking at a random memory location "(* p)" could likely crash your program, but it won't be anything useful that you should use. So when you say "* p" = 'c'; you say overwrite the memory location (which is randomly chosen) with the ascii code for the character 'c'.
Side note - the surprising markup language here doesn't let you use asterisk p directly, you have to put a space in I just discovered.