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 radit[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 :
  1. Pointer variable is a pointer that can be assigned with new value
  2. Pointer constant is a pointer that can not be assigned with new value
  3. 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 radit;
      int *pointer{4];
How to access an array using a pointer
            int radit[9090];
            int *ptr_radit;

Im writing this in english so that everyone can learn from it. Hope you learn something today!

2201741933
Raditya Saskara
binus.ac.id
skyconectiva.com

-trust me, its not easy.


reference : 

Paul Deitel & Harvey Deitel. (2016). C how to program : with an introduction to C++. 08. Pearson  Education. Hoboken. ISBN: 9780133976892. Chapter 6 & 7

Komentar