This time, we learned about pointers and array. Pointers and array has some similarity though both of them are different.
Pointer is basically pointer which it points at other things. In this case, pointer is a variable that points other variable. Pointer’s value is the other variable’s (that it points at) address. This makes the value that is given to the pointer affect the value of the variable it points at, and same thing the other way around.
For example:
int x, *p; // * means pointer variable
p = &x; // means the pointer p value is filled with variable x address
*p = 5; // means x = 5 because x is pointed by pointer p
Double pointer is a pointer that points at another pointer.
For example:
int x, *p, **d; // ** means double pointer
p = &x;
// double pointer d points at pointer p
d = &p; // means the double pointer d value is filled with pointer p address
**d = 3; // means *p = 3; and x = 3;
Array is a group of data formed in a certain grouping. Array can be made one dimension, two or even three dimension. Array data type is homogenous means it has the same data type. Array data can also be access individually.
For example:
int a[5]; // means a is an integer array with 10 slots of data
/* Slots of data:
a[0]; a[1]; a[2]; a[3]; a[4]; */
a[1] = 3; // means a[1] value is filled with 3
*(a+2) = 4; // means a[2] value is filled with 4
//*a = a[0] and *(a+1) = a[1]
int b[5] = {1, 3, 5, 7}; // means array b is filled with 4 data (1, 3, 5, and 7) while the last data is 0 by default
int c[2][3]; // means c is an integer array with two dimension, two rows and three column
/* slot of data:
c[0][0]; c[0][1]; c[0][2];
c[1][0]; c[1][1]; c[1][2];
There are two types of pointer. Pointer variable is a pointer that can be assigned to point other variable inside the program. Pointer constant is a pointer that can’t be assigned to point other variable inside the program means that it can only point a variable and can’t be change later when the program is execute. Array is an example of pointer constant.
There are also array of pointer. This means that pointers can be made as array and it can works as an array as well.
There are also a special type of array which is string or array of character (char). String must be ended with NULL or . Through string we can do some string manipulation using string.h library. There are strrev for reversing string, strlen to find out the length of the string, strcpy to copy a string to another, strcat to insert string to another string, strcmp to compare two different string and others.
That is all of this meeting. Thanks. Cheers!