Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring a pointer syntax in a function

Tags:

c

Are both pointer statements the same?

void reverse(const char * const sPtr){


}

and

void reverse(const char const *sPtr){


}
like image 290
runners3431 Avatar asked Jan 18 '12 19:01

runners3431


People also ask

Can we declare function as pointer?

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.

What is pointer with syntax and example?

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!

How do we declare a pointer in C?

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.

How do you define a function pointer in C++?

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 .


1 Answers

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."

like image 168
ouah Avatar answered Sep 21 '22 16:09

ouah