C: Pointers & Arrays
- Pointer
Variables which store the addresses of other variables (including other pointers). Initialized by *(variable name).
int x;
int *aa;
aa = &x;
*aa is a pointer which stores the address of x.
- Array
Groups of variables stored with same variable names. Initialized by (variable name)[array size].
int aa[5];
aa is an array which can store up to five integer variables.
- Two-Dimensional & Three-Dimensional Arrays
Two-Dimensional Arrays can be initialized by (variable name)[length][width]. The amount of variables which can be stored is length*width.
Three-Dimensional Arrays can be initialized by (variable name)[length][width][height]. The amount of variables which can be stored is length*width*height.
- Accessing Arrays
aa[(array size)];
Variables are stored in aa[0] to aa[(array size - 1)].
Any element of an array can be accessed through either *(aa+x) or aa[x], where x is (element number - 1).
For example, to access the second element, either *(aa+1) or aa[1] can be used (the element number is 2, 2 - 1 = 1).
- String
Array of char variables ending with \0. Initialized with char (string name)[string length].
2201757635
skyconnectiva.com
binus.ac.id
Juanda P. G.
Variables which store the addresses of other variables (including other pointers). Initialized by *(variable name).
int x;
int *aa;
aa = &x;
*aa is a pointer which stores the address of x.
- Array
Groups of variables stored with same variable names. Initialized by (variable name)[array size].
int aa[5];
aa is an array which can store up to five integer variables.
- Two-Dimensional & Three-Dimensional Arrays
Two-Dimensional Arrays can be initialized by (variable name)[length][width]. The amount of variables which can be stored is length*width.
Three-Dimensional Arrays can be initialized by (variable name)[length][width][height]. The amount of variables which can be stored is length*width*height.
- Accessing Arrays
aa[(array size)];
Variables are stored in aa[0] to aa[(array size - 1)].
Any element of an array can be accessed through either *(aa+x) or aa[x], where x is (element number - 1).
For example, to access the second element, either *(aa+1) or aa[1] can be used (the element number is 2, 2 - 1 = 1).
- String
Array of char variables ending with \0. Initialized with char (string name)[string length].
2201757635
skyconnectiva.com
binus.ac.id
Juanda P. G.
Comments
Post a Comment