Why Pointers
1. Pointers are more efficient in handling arrays and data tables.
2. Pointers can be used to return multiple values from a function via function arguments.
3.Pointers permit references to functions and thereby facilitating passing of function s argument to another function.
4.The use of pointer arrays to character strings results in saving of data storage space in memory.
5.Pointers allow C to support dynamic memory managment.
6. Pointers reduce length and complexity of programs
7. They reduce the execution speed and thus reduce the program execution time.
Pointer Constant Pointer values Pointer Variable
Memory addresses within a computer are referred to as pointer constants. We can not change them; we can only use them to store data values. They are like house numbers.
We cannot save the value of a memory address directly. We can only obtain the value through the variable stored there using the address operator &. The value thus obtained is known as pointer value. The pointer value(i.e. the address of a variable) may change from one run of the program to another.
Once we have a pointer value, it can be stored into another variable. The variable that contains a pointer value is called pointer variable.
Rules of Pointer Operations
1. A pointer variable can be assigned the address of another variable.
2. A pointer variable can be assigned the values of another pointer variable.
3. A pointer variable can be initialized with NULL or zero value.
4. A pointer variable can be pre-fixed or post-fixed with increment or decrement operators
5. An integer value may be added or subtracted from a pointer variable.
6. When two pointers point to the same array, one pointer variable can b e subtracted from another.
7. When two pointers points to the objects of the same data types, they can be compared using relational operators.
8. A pointer variable can not be muktiplied by a constant
9. Two pointer variables can not be added
10. A value can not be assigned to an arbitary address
No comments:
Post a Comment