Re:Everything I wish I knew when learning C
by fwip on Monday November 28, 2022 @12:34PM
(#33776572)
Gotcha, so it's kind of like:
int (*(x = &(a)));
i i p p i // i means int, p means pointer
Re:Everything I wish I knew when learning C
by thomastjeffery on Monday November 28, 2022 @01:49PM
(#33777780)
I prefer to think of it as
(int *) x = &(a);
i p p a i // a means address
Which is why I prefer to write int* x = &a;
"integer pointer" named "x" set to address of integer "a".---
As a sibling comment pointed out, this is ambiguous when using multiple declaration:
int* foo, bar;
The above statement declares an "integer pointer" foo and an "integer" bar. It can be unambiguously rewritten as: int bar, *foo;
But multiple declaration sucks anyway! It's widely accepted good practice to set (instantiate) your variables in the same statement that you declare them. Otherwise your program might start reading whatever data was lying around on the stack (the current value of bar) or worse: whatever random memory address it refers to (the current value of foo).
a is int; &a is pointer to int; x is pointer to int; *x in again int.