Are both pointer statements the same?
void reverse(const char * const sPtr){
}
and
void reverse(const char const *sPtr){
}
Function pointers in C need to be declared with an asterisk symbol and function parameters (same as function they will point to) before using them in the program. Declaration of function pointers in C includes return type and data type of different function arguments.
Example of pointer in Cint* point = &a; // pointer variable point is pointing to the address of the integer variable a! int a=5; int* point = &a; // pointer variable point is pointing to the address of the integer variable a!
The * symbol indicates that the variable is a pointer. To declare a variable as a pointer, you must prefix it with *. In the example above, we have done a pointer declaration and named ptr1 with the data type integer.
The Basic syntax of function pointers We can think of function pointers like normal C++ functions. Where void is the function's return type. *fun_ptr is a pointer to a function that takes one int argument. It's as if we are declaring a function called *fun_ptr which takes int and returns void .
No.
const char const *sPtr
is equivalent to
const char *sPtr
.
const char *sPtr
say parameter sPtr
is a pointer to a const char
.
const char * const sPtr
is a const
pointer to a const char
.
Note that this is equivalent in C99 and C11:
(C99, 6.7.3p4) "If the same qualifier appears more than once in the same specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it appeared only once."
but not in C89 where const char const *sPtr
is a constraint violation:
(C90, 6.5.3) "The same type qualifier shall not appear more than once in the same specifier list or qualifier list, either directly or via one or more typedefs."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With