#include <stdio.h>
void eg(int i) {
int *j; // "j is a pointer and (hence) *j is an int"
j = &i; // "Put the address of i into *j? Yup"
*j = *j + 1;
printf("%d\n", *j);
}
int main() {
eg(4);
}
Perhaps this is because I am just used to it, but I really see very little room for confusion here. The common usage avoids confusion, if you do not insist on assignment at the time of declaration.
To address your second confusion, just keep in mind that strings are char arrays and an array's name is actually a pointer. Again, I find this very straightforward.
I don't understand how you reach that conclusion. You might understand it, I don't see how you can say there is very little room for confusion.
Yes, if you know about declaration follows use, it makes sense.
Yes, if you "keep in mind that strings are char arrays and an array's name is actually a pointer" then it makes sense.
You can get by by knowing to avoid some constructs.
If you know how the c compiler works, pointers make sense.
If you know C then you know C.
But when you're new to the language, you don't know these things and that's what this part of the thread is discussing.
Another responder wrote:
The key is that * is part of the type of the
declaration, not of the variable; an int* is
not an int.
The grammar is structured as though it's not. Consider this:
int* c, d;
Since star is part of the type, if the language was designed well then both of them would be int pointers. But in that case, only c is. d is an int. Awful.
>> I really see very little room for confusion here.
> I don't understand how you reach that conclusion. You might understand it, I don't see how you can say there is very little room for confusion.
Please do not put words in my mouth. I wrote "I see very little room for confusion" not "There is very little room for confusion". I tried to make it clear that I was talking about my personal experience; and I was talking about my personal experience since I was hoping it would help, not to defend the syntax of C.
Sometimes a particular point of view allows you to understand something; in some cases it makes the previously mystifying point "trivial" or "obvious". I am sorry that the POV that helped me so much does not help you at all.
Do you mean to reinforce that the language is not beginner-friendly, or are you really asserting that makes the language poorly-designed? If it's the latter, you should really at least explore some other factors before making the conclusion. It seems to me that it's a relatively minor distinction once you know it, so from a design perspective that may simply be a tradeoff for some other advantage.
To address your second confusion, just keep in mind that strings are char arrays and an array's name is actually a pointer. Again, I find this very straightforward.