A function f() will can be defined as returning a pointer to a character with the syntax
char *f()
{
}
One must be careful in creating these functions that the character pointer is set to point to a static variable or an allocated string; an automatic variable will vanish when the function exits, leaving the pointer invalid.
I should point out that this is very basic C syntax. If this question is being asked as part of a school assignment, I must suggest that perhaps you should drop this course now, as it will be immeasurably harder as you get further into it.
Pointer to Pointer is a double pointer, denoted by (**). Pointer stores the address of the variable and pointer to pointer stores the address of a pointer variable and syntax can be given as int **ptr2ptr;
constant pointer and character pointer
The asterisk (*) operator dereferences a pointer and returns the value stored in the memory pointed to by the pointer.
No, 'void *' and 'double *' are ok; 'void double *' is syntax error.On the other hand 'void **p' is totally correct: p holds the address of a generic pointer.
char *ptr;
Pointer to Pointer is a double pointer, denoted by (**). Pointer stores the address of the variable and pointer to pointer stores the address of a pointer variable and syntax can be given as int **ptr2ptr;
fgetc gets a character from a file using a file pointer.the syntax is fget(fp) where fp is a pointer to the file
Answerchar (*funcp(int));
constant pointer and character pointer
int main (int argc, char **argv):Hereargv is a pointer to a pointer (points to the first element of a pointer-array)argv[0] is a pointer (points to the first character of a string)argv[0][0] is a character
int mystrlen (const char *s) { const char *t; if (!s) return 0; for (t=s-1;*++t;); return t-s; }
The asterisk (*) operator dereferences a pointer and returns the value stored in the memory pointed to by the pointer.
No, 'void *' and 'double *' are ok; 'void double *' is syntax error.On the other hand 'void **p' is totally correct: p holds the address of a generic pointer.
char *ptr;
In C programming, a string doesn't have a specific return type as it's essentially an array of characters. So, if a function is returning a string, it should be declared to return a pointer to a char (char*), since a string in C is represented as an array of characters terminated by a null character ('\0').
void as function return-type means no return value void as function parameter means no parameter void * as pointer type means generic pointer
void is type of pointer that usually means that you can make it point to any data type. When you make a pointer point to somewhere its data type should match with the place where you want it to point. When you dont know the data type where it will point to then you can declare a void pointer and make it point to the data type it want.