Pointers and Arrays:
–Pointer Definition
–Pointer Concept
–Pointer to Pointer
–Array
Pointer Definition
- Pointer is a variable that store the address of another variable
- Syntax :
<type> *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 */
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:
–Homogenous
All elements have similar data type
–Random Access
Each element can be reached individually, does not have to be sequential
- Syntax:
type array_value [value_dim];
- Example :
int A[10];
- The definition consists of 4 components:
–Type specified
–Identifier (name of the array)
–Operator index ([ ])
–Dimensional value inside operator [ ]