Monday, October 29, 2018

Pointer and Array

What is the pointer?

A pointer is a value that designates the address (that is, the location in memory) of a certain value. Pointers are variables that contain a memory location. Pointers can reference any type of data, including functions.


Pointer types are often used as a parameter for function calls.  As you pass on arguments to C, in order for a function to modify the value from the calling, the value index must be passed. References to structures are also used as function arguments even if there is nothing in the structure that changes in the function. This is so as to avoid copying the entire contents of the structure onto the stack. 

Pointer Deferencing
-->
To access a value to which a pointer points, the * operator is used. Another operator, the -> operator is used in conjunction with pointers to structures. Here's a short example.
 c   = 10;
 pj  = &c;             /* pj points to c */
 d   = *pj;            /* d is assigned the value to which pj points, 10 */
 pj  = &d;             /* now points to d */
 *pj = 12;             /* d is now 12 */


-->
What is array?


An array is a container object that contains a specified number of values of a specified value. The array length is created when the array is created. After the creation, the length is fixed.
Illustration of an array as 10 boxes numbered 0 through 9; an index of 0 indicates the first element in the array
An array of 10 elements.

-->
Each element in the array is called an element, and its numeric index is available for each element. As shown in the previous figure, the numbering starts with 0. For example, item 9 is available for index 8.






By :Steven
2201852132
Computer Science and Statistics



No comments:

Post a Comment