I am learning C today. I have been coding managed languages โโ(Java, C #, Python, etc.) for some time now. I thought I understood the details of pointers, but then I wrote the following code, which worked as expected, but generated a warning "incompatible pointer type".
void setText(char* output) { //code to set output to whatever, no problems here. } int main(int argc, const char* argv[]) { char output[10]; setText(&output); //[EDITED] ...other test code which printf and further manipulates output. return 0; }
So I googled and ended up changing the line
setText(&output);
to
setText(output);
who got rid of the warning. But now I donโt know why the first one worked at all. I sent the address of the address as far as I can tell (because char * x; essentially the same as char x [];). What I donโt understand and why both of these work?
atheaos
source share