Pointers and Arrays
Pointer
Pointer is a variable that store the address of another variableExample of Pointer :
int number1, *number2;
char word1, *word2;
Pointer to Pointer
Pointer to pointer is variabel that saves another address of a pointerExample :
int number1, *number2, **number3;
char word1, *word2, **word3, ***word4;
So, what will happen when we add another pointer on a pointer ?
Example :
number1 = 7;
number1 = *number2;
*number2 = **number3;
**number3 = ***number4;
when this happens then any number (1/2/3/4) will become 7 (they will follow the number 1) since number 2 is following number 1 ,and number 3 is following number 2 and so on.
Array
Array is a data saved in a certain structure to be accessed as a group or individually. Some variables saved using the same name distinguish by their index.
Example of Array :
int number[10];
Array can be used to make elements
Example :
Example :
int A[ ]={5, 2, -1, 9};
there are two ways to apply "i=2;"
*(A+2) or A[2]
String
String is an array of character that
ended with null character (
‘\0’ or in ASCII = 0)
A Constant String can be linked at
compile-time:
"Hello," " world"
Similar to:
"Hello,
world"
Example string initialization:
char
s[ ] = "BINUS";
Similar to :
char s[ ] =
{'B','I','N','U','S','\0'};
What is the difference between Char and String ?
Character
in c written between single quote.
Each uses one byte of computer memory
String
written in between double quote.
- Thanks for Reading -