No. For var to be constant the declaration of f should be
int f ( int *const var)
Yes. * var is constant. _and (*var)++ is bad.
Also, *var++ is not incrementing the *var. It's actually incrementing
the var and then dereferencing. ++
precedes over *, see operator precedence.
No. For this the declaration of _f would be
int f ( const int *const var)
For * var to be constant
int f ( const int *var)
I would quote my professor who explained reading params to avoid
confusion.
1. Read the variable, in this case _var
2. Bounce first left and then right and then continue in this same
fashion
3. Keep identifiers associated with keywords/variables.
So this would read as
1. var
2. bounce left, * => pointer
3. bounce right, nothing
4. bounce left, const int. Note. identifier const associated with int.
You can continue similarly for _f and get the function.
"f is a function returning int taking params"
param= pointer to constant int as param
so f is
"f is a function returning int taking pointer to constant int as param"
Complete the sentence:
This make "var is a pointer to constant int"
For:
int f ( const int *const var)
1. var
2. bounce left, const
3. bounce right, nothing
4. bounce left, * => pointer
3. bounce right, nothing
4. bounce left, const int. Note. identifier const associated with int.
Complete the sentence:
This make "var is a constant pointer to constant int"
For:
int f ( int *const var)
1. var
2. bounce left, const
3. bounce right, nothing
4. bounce left, * => pointer
3. bounce right, nothing
4. bounce left, int.
Complete the sentence:
This make "var is a constant pointer to int"
HTH.
Regards,
Taran