Pointers and Arrays:
-Pointer Definition
-Pointer Concept
-Pointer to Pointer
-Array
Pointer is a variable that store the address of another variable
Syntax :
*ptr_name;
Two operators mostly used in pointer : * (content of) and & (address
of)
Example:
Initialize an integer pointer into a data variable:
int i, *ptr;
ptr = &i;
To assign a new value to the variable pointed by the pointer:
*ptr = 5; /* means i=5 */
Pointer to pointer is a variable that saves another address of a
pointer
Syntax:
**ptr_ptr ;
Example:
int i, *ptr, **ptr_ptr;
ptr = &i;
ptr_ptr = &ptr;
To assign new value to i:
*ptr = 5;
// means i=5 ;
**ptr_ptr = 9;
// means i=9; or *ptr=9;
Array Definition
Data saved in a certain structure to be accessed as a group or
individually. Some variables saved using the same name
distinguish by their index.
Array characteristics:
All elements have similar data type
Random Access
Each element can be reached individually, does
not have to be sequential
Pointer Constant & Pointer Variable
Pointer variable is a pointer that can be assigned with new
value at run-time.
Pointer constant is a pointer that can not be assigned with
new value at run-time
Array is Pointer Constant to its first element of the array.
Array can be filled with pointer variable.
Example:
int x=10, y=20;
int *ptr;
ptr = &x;
ptr = &y;