UNIT-7 POINTER
1
,What is Pointer?
▪ A normal variable is used to store value.
▪ A pointer is a variable that store address / reference of another
variable.
▪ Pointer is derived data type in C language.
▪ A pointer contains the memory address of that variable as their
value. Pointers are also called address variables because they
contain the addresses of other variables.
▪ A pointer is a variable whose value is the address of another
variable, i.e., direct address of the memory location.
, Declaration & Initialization of Pointer
▪ Like any variable or constant, you must declare a pointer before using it to store
any variable address.
▪ The general form of a pointer variable declaration is −
Syntax
datatype *variablename;
▪ Here, datatype is the pointer's base type; it must be a valid C data type
and variablename is the name of the pointer variable.
▪ The asterisk * used to declare a pointer is the same asterisk used for
multiplication.
▪ However, in this statement the asterisk is being used to designate a variable as a
pointer.
int *ip; /* pointer to an integer */
float *fp; /* pointer to a float */
double *dp; /* pointer to a double */
char *cp; /* pointer to a character */
1
,What is Pointer?
▪ A normal variable is used to store value.
▪ A pointer is a variable that store address / reference of another
variable.
▪ Pointer is derived data type in C language.
▪ A pointer contains the memory address of that variable as their
value. Pointers are also called address variables because they
contain the addresses of other variables.
▪ A pointer is a variable whose value is the address of another
variable, i.e., direct address of the memory location.
, Declaration & Initialization of Pointer
▪ Like any variable or constant, you must declare a pointer before using it to store
any variable address.
▪ The general form of a pointer variable declaration is −
Syntax
datatype *variablename;
▪ Here, datatype is the pointer's base type; it must be a valid C data type
and variablename is the name of the pointer variable.
▪ The asterisk * used to declare a pointer is the same asterisk used for
multiplication.
▪ However, in this statement the asterisk is being used to designate a variable as a
pointer.
int *ip; /* pointer to an integer */
float *fp; /* pointer to a float */
double *dp; /* pointer to a double */
char *cp; /* pointer to a character */