Pointers and Arrays
1. Arrays :
Arrays are 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.
Array characteristics:
– Homogenous : All elements is the same
– Random Access
How to write an array :
type array_value [value_dim];
example :
int me[20];
How to assign a value:
• Example : A[6] = 30; A[3] = 909;
this is an example of one dimensional array :
#include<stdio.h>
int SIZE = 12;
void main() {
int x, y;
int n[SIZE] = {15, 90, 11, 47, 55};
for( x=0 ; x<= SIZE ; x++) {
printf("%12d ", n[x]);
for ( y=1; y<=n[x] ; y++) printf("%c","*");
printf("\n");
}
}
2. Pointers :
Pointers are divided into three :
- Pointer variable is a pointer that can be assigned with new value
- Pointer constant is a pointer that can not be assigned with new value
- Array is Pointer Constant to its first element of the array and can be filled with pointer variable.
How to write pointers
type *array_name [value_dim];
int me;
int *pointer{4];
How to access an array using a pointer
int me[9090];
int *ptr_me;
Tidak ada komentar:
Posting Komentar