A pointer is simply a primitive variable, not unlike an int. Its length (in bits) is determined by the underlying architecture: typically 32 bits on a 32-bit system or 64 bits on a 64-bit system. Just as an int variable stores a numeric value in memory, a pointer stores a memory address in memory. The pointer is said to "point at" that address, and can be dereferenced to indirectly access the actual value stored at that address (known as indirection). A pointer can point to a memory address containing another pointer, adding another level of indirection.
An array is simply a contiguous block of memory divided into one or more elements. The array name is a reference to the start address of that block, which is also the address of the first element in the array. Just as an array can contain one or more int types, an array can also contain one or more pointer types. This is typically used in C-style dynamic multi-dimensional arrays, where each pointer points to the start address of another array. Unlike static multi-dimensional arrays which are allocated in a single block for all dimensions, arrays of pointers can point to arrays stored anywhere on the heap. This makes it possible to store enormous arrays non-contiguously (each array being pointed at is itself contiguous but the array as a whole is non-contiguous).
A pointer to pointer has many uses, one of the simplest being 2D arrays (matrices). Compacting garbage collectors also often employ pointer pointers.
Because of pointers and that all arrays are really pointers. A pointer something like *pointer can also be written as pointer[0] and *(pointer + 1) can also be written as pointer[1]
An array is a contiguous block of memory containing one or more elements of the same type. The array identifier is a reference to that block of memory. References do not require any memory other than the memory they reference. References are not variables -- they are merely aliases for memory addresses. A pointer is a variable that can store any reference and provides indirect access to that reference. Pointers can be used to allocate arrays dynamically, which means memory is required not only for the array, but also for the pointer to store the starting memory address of the array. Once allocated, the array can be referenced directly, but the pointer is still required in order to release the memory allocation when it is no longer required. Arrays employ pointer arithmetic to locate individual elements by their zero-based index, which is essentially an offset from the reference multiplied by the size of the element type. However arrays and pointers are not the same from a programming standpoint. Your compiler may well implement references as pointers, but that is only of concern to compiler authors, not programmers. Two-dimensional dynamic arrays make use of a pointer-to-pointer variable to point to a one-dimensional array of pointers, each of which points to a one-dimensional array of the actual elements. A three-dimensional array employs a pointer-to-pointer-to-pointer to point to a one-dimensional array of pointer-to-pointer variables, each of which points to a two-dimensional array. And so on. Static arrays use less memory as there is no need to maintain arrays of pointers, but static arrays are only useful when the number of elements and dimensions are known at compile time. At runtime, arrays of pointers are required over and above the array elements themselves, in order to both allocate and deallocate the memory, as well as obtain references to the elements in the array. Pointers also have uses beyond that of dynamic arrays, including allocating any type of memory of any size, and pointing at functions which can then be passed as arguments to other functions.
A pointer can point to any element of the array, the array itself is a constant pointer. Eg.: int a[10], *p; p= &a[3]; p= a; /* the same as p= &a[0] */ a[2]= *p; a[3]= p[4]; a= p; /* WRONG! */
If the array is static you can simply point at the first element. For dynamic arrays you can allocate a contiguous block to a single pointer which can then be subdivided using a one-dimensional array of pointer to pointers, each of which points to a one-dimensional array of pointers, each of which points to a separate object within the array. For extremely large arrays, however, it is better to split the elements into separate one-dimensional arrays, by creating a one-dimensional array of pointer to pointers first, then allocating each of those pointers to a separate one-dimensional array of pointers, each of which points to a separate one-dimensional array of objects. Either way, you must destroy all the individual arrays in the reverse order of creation.
Simply by sending the base address from main() and catching that in a pointer in the pointer. void main() { int a[20]; sort(a); } void fun(int *p) { }
Yes. All string variables are pointers as are other arrays.
... are usable. void pointer (generic pointer) : a special type of pointer which point to some data of no specific types. void *p; null pointer : a special type of pointer which point nowhere. it is usually used to check if a pointer is pointing to a null or free the pointer during deallocation of memory in dynamic memory allocation; it is define by using the predefine constant NULL int *p=NULL; wild pointer : uninitialized pointer. it hold a garbage value. i.e it is not pointing to any memory location yet. dangling pointer: pointer pointing to a destroyed variable. it usually happen during dynamic memory allocation when the object is destroyed but not free and the pointer is still pointing to the destroy object.
the simple and efficient way to pass an array is pointer to an array like that int (*p)[30] ; // pointer to an array of integer having 30 element
No
yea that's why its called the point FINGER
You don't need to use ampersand for arrays; it's entirely optional even for strings (character arrays). This is because arrays will implicitly convert to a pointer at the slightest provocation. Thus for an array named X, you can either pass the array to a function as X, &X or &X[0], they all refer to the exact same address.