4 ms·
Not at all! a is int; &a is pointer to int; x is pointer to int; *x in again int.
by pif 4y ago
Not at all!
a is int; &a is pointer to int; x is pointer to int; *x in again int.
- fwip 4y agoGotcha, so it's kind of like: int (*(x = &(a))); i i p p i // i means int, p means pointer
- thomastjeffery 4y agoI 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).
- fwip 4y agoThanks :)