Explain pointer declaration in C?
(Don't copy from google)
Answers
Answered by
2
Pointer Declarations
Pointer declaration is similar to other type of variable except asterisk (*) character before pointer variable name.
Here is the syntax to declare a pointer
data_type *poiter_name;
Let's consider with following example statement
int *ptr;
Here, in this statement
ptr is the name of pointer variable (name of the memory blocks in which address of another variable is going to be stored).
The character asterisk (*) tells to the compiler that the identifier ptr should be declare as pointer.
The data type int tells to the compiler that pointer ptr will store memory address of integer type variable.
Finally, ptr will be declared as integer pointer which will store address of integer type variable.
Pointer ptr is declared, but it not pointing to anything; now pointer should be initialized by the address of another integer variable.
Consider the following statement of pointer initialization
int x;
int *ptr;
ptr=&x;
Here, x is an integer variable and pointer ptr is initiating with the address of x.
Here are a few examples:
int *ip // pointer to integer variable
float *fp; // pointer to float variable
double *dp; // pointer to double variable
char *cp; // pointer to char variable
Pointer declaration is similar to other type of variable except asterisk (*) character before pointer variable name.
Here is the syntax to declare a pointer
data_type *poiter_name;
Let's consider with following example statement
int *ptr;
Here, in this statement
ptr is the name of pointer variable (name of the memory blocks in which address of another variable is going to be stored).
The character asterisk (*) tells to the compiler that the identifier ptr should be declare as pointer.
The data type int tells to the compiler that pointer ptr will store memory address of integer type variable.
Finally, ptr will be declared as integer pointer which will store address of integer type variable.
Pointer ptr is declared, but it not pointing to anything; now pointer should be initialized by the address of another integer variable.
Consider the following statement of pointer initialization
int x;
int *ptr;
ptr=&x;
Here, x is an integer variable and pointer ptr is initiating with the address of x.
Here are a few examples:
int *ip // pointer to integer variable
float *fp; // pointer to float variable
double *dp; // pointer to double variable
char *cp; // pointer to char variable
Similar questions