well;
C is a language of "expressions", for it offers the facility to explore, the practicability to implement, and the depth of low-levelness. Pointer is one such concept that can offer an approach to more compact and efficient code.
A pointer, in its simplest form, is an object capable of holding an lvalue of a compatible object. In C, the address-of operator (&) gives the address of an object. The following example shows it how:
int k;
int *p; /* p is pointer to an int */
p = &k; /* p points to k */
*p = 3; /* k is now 3 */
The second statement declares p as a pointer to an integer. The address-of operator gives the address of k which is stored in the pointer p; p is now said to point to k. The asterisk(*) in the expression, *p, is called a dereference operator which retrieves the value pointed by the pointer. Now, *p can occur in any context or expression where k could.
Pictorially,
addr ess: 0x1000 0x2000
__________ k __________
| 3 | <---- | 0x1000 |
---------- | ----------
| | p
|______________|
points to
Since, both, p and k are objects, an implementation-defined memory storage unit is allocated to each as shown. The objects k and p reside at the addresses 0x1000 and 0x2000, respectively; and, p is shown pointing to k.
An array is a nonempty set of sequentially indexed elements having the same type of data. Each element of an array has a unique identifying index number. Changes made to one element of an array do not affect the other elements.
In C, the declaration
int a[10];
defines an array of size 10, each of which is an integer object. These objects -- named a[0], a[1], ..., a[9] -- appear contiguously in the storage area, that is, there is no padding between the array members.
An array type is called as an aggregate type since it is considered to be derived from it's element type. If the element type is T, then the array type is called as "array of T". For example, in the above declaration element type of a is integer, so the array a is called as "array of integers".
An array must not be declared/defined with the `register' storage class specifier; doing so is an undefined-behavior.
Answered by
Kishore
, an ibibo Master,
at
8:05 AM on August 22, 2008