Algorithm & Programming (Array and Pointer)

Algorithm & Programming (Array and Pointer)

Pointer

Pointer is variable that store address of another variable.
Pointer which is mostly used : *(content of) and &(address of).
Example:
int i, *ptr;
ptr = &i;
To assign a new value to the variable pointed by the pointer:
*ptr = 5;  /* means i=5 */ 

Pointer to pointer is pointer for address to another pointer.

Pointer constant : a pointer that can be assigned with new value at run-time. Array is pointer constant.
Pointer variable : a pointer that can not be assigned with new value at run-time.

Array

Array is data saved to be access as a group or individually.
Characteristic:
1. Homogenous = all element have similar data type.
2.Random access = doesn't have to be sequential.

Array Initialization
Example : B[4]={1,2,5,}

One Dimensional Array
Syntax: type array_value [value_dim];

Example : int number[10000];

Two Dimensional Array
Syntax : type name_array[row][col];
Example: int number[7][7];






References
Paul Deitel & Harvey Deitel. (2016). C how to program : with an introduction to C++. 08. Pearson Education. Hoboken. ISBN: 9780133976892. Chapter 6 & 7
Storing Similar Data Items: http://aelinik.free.fr/c/ch12.htm


Name : Samuel Xavier Widjaja
NIM : 2201737412
binus.ac.id
skyconnectiva.



Comments