Click here to Skip to main content
15,888,802 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: C declarations are half backward Pin
Mike Winiberg29-Nov-20 21:18
professionalMike Winiberg29-Nov-20 21:18 
GeneralRe: C declarations are half backward Pin
honey the codewitch30-Nov-20 4:00
mvahoney the codewitch30-Nov-20 4:00 
GeneralRe: C declarations are half backward Pin
Mike Winiberg30-Nov-20 4:33
professionalMike Winiberg30-Nov-20 4:33 
GeneralRe: C declarations are half backward Pin
W Balboos, GHB30-Nov-20 5:20
W Balboos, GHB30-Nov-20 5:20 
GeneralRe: C declarations are half backward Pin
Joop Eggen29-Nov-20 23:25
Joop Eggen29-Nov-20 23:25 
GeneralRe: C declarations are half backward Pin
Rusty Bullet30-Nov-20 3:52
Rusty Bullet30-Nov-20 3:52 
GeneralRe: C declarations are half backward Pin
honey the codewitch30-Nov-20 3:55
mvahoney the codewitch30-Nov-20 3:55 
GeneralRe: C declarations are half backward Pin
Kirk 1038982130-Nov-20 4:18
Kirk 1038982130-Nov-20 4:18 
You are thinking about it the wrong way, I believe.

There is an implicit Algebra: * = 1/&

so, char *p, LITERALLY says (*p) is a char.
therefore &(*p) => Address of that char!
but knowing the algebra & and * cancel each other out (as do & and [)

So, p is a pointer to a specific char. And the beauty of this, is that how you declare it usually implies how you are going to use it. A fixed array is declared as char a[10]; Which again, says (to me), I want an array of 10 characters, a POINTS to the first character, and a[1] == *(a+1).

I always found this part of C very expressive and self-explanatory.

Of course, I learned PDP/11 Macro-11 Assembly BEFORE I learned C. So most of this was mapping to register level access of R0 vs (R0) [Memory direct and indirect addressing].
Mov 65, R0 ; Stores the value in the register
Mov 65, (R0) ; Stores 65 at the memory location of R0
Mov 65, (R0++) ; Stores 65 at the memory location and increments the memory location AFTER to the next

; Note its been 35 years, the syntax is illustrative of the features.

If you know how the variable is declared, you should instantly understand the various ways you can dereference it.

GeneralRe: C declarations are half backward Pin
honey the codewitch30-Nov-20 4:26
mvahoney the codewitch30-Nov-20 4:26 
GeneralRe: C declarations are half backward Pin
Kirk 1038982130-Nov-20 4:37
Kirk 1038982130-Nov-20 4:37 
GeneralRe: C declarations are half backward Pin
honey the codewitch30-Nov-20 4:46
mvahoney the codewitch30-Nov-20 4:46 
GeneralRe: C declarations are half backward Pin
Kirk 1038982130-Nov-20 6:37
Kirk 1038982130-Nov-20 6:37 
GeneralRe: C declarations are half backward Pin
honey the codewitch30-Nov-20 6:39
mvahoney the codewitch30-Nov-20 6:39 
GeneralRe: C declarations are half backward Pin
BernardIE531730-Nov-20 5:50
BernardIE531730-Nov-20 5:50 
GeneralRe: C declarations are half backward Pin
honey the codewitch30-Nov-20 5:51
mvahoney the codewitch30-Nov-20 5:51 
GeneralRe: C declarations are half backward Pin
BernardIE531730-Nov-20 6:02
BernardIE531730-Nov-20 6:02 
GeneralRe: C declarations are half backward Pin
honey the codewitch30-Nov-20 6:04
mvahoney the codewitch30-Nov-20 6:04 
GeneralRe: C declarations are half backward Pin
BernardIE531730-Nov-20 6:22
BernardIE531730-Nov-20 6:22 
GeneralRe: C declarations are half backward Pin
honey the codewitch30-Nov-20 6:24
mvahoney the codewitch30-Nov-20 6:24 
GeneralRe: C declarations are half backward Pin
BernardIE531730-Nov-20 8:38
BernardIE531730-Nov-20 8:38 
GeneralRe: C declarations are half backward Pin
Stuart Dootson30-Nov-20 5:53
professionalStuart Dootson30-Nov-20 5:53 
GeneralRe: C declarations are half backward Pin
Stuart Dootson30-Nov-20 5:52
professionalStuart Dootson30-Nov-20 5:52 
GeneralRe: C declarations are half backward Pin
honey the codewitch30-Nov-20 5:54
mvahoney the codewitch30-Nov-20 5:54 
GeneralRe: C declarations are half backward Pin
Member 1330167930-Nov-20 8:18
Member 1330167930-Nov-20 8:18 
GeneralRe: C declarations are half backward Pin
honey the codewitch30-Nov-20 8:26
mvahoney the codewitch30-Nov-20 8:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.