Senin, 22 Oktober 2018

Array and Pointer


Hello everyone welcome to my Blog !!!
This is the new blog that consist every Coding tutorial !!!
It's the same with my JPrepetition blog, but that one consist only repetition tutorial.

And now in this blog I will post every coding tutorial that I could....
So keep reading okay !!!

So now our theme is Array and Pointer....

What is Array ??
Array is data that is saved in a certain structures to be accesed as a group or individually. Some variables saved using the same name distinguish by their index. And array is a collection of data that holds fixed number values of same types

Array Charateristic ??
1. Array is homogeneous, it means all elements have similar data type.
2. Array s a random access type, it means that each element can be reached individually, does not have to be sequential. 

The Syntax of Array 
- type array_value [value_dim]; or dataType arrayName[arraySize];

The Example of Array Coding 
int arry[15];
   for ( int a = 0; a <15; a++) arry[a] = 0;

And in here the meaning is integer arry with size 15 is, meaning it can hold 100 integer values.
And integer a will loop or fill the arry until it's maximum (15).  

The elements of Array :
Suppose you declared an array arry as above. The first element arry[0], second element arry[1], third element arry[2], and so on until 15.

It's possible to initialize an array during declaration, For example :
int arry[15] = {1, 3, 5, -7} or int arry[] = {2, 3, 7, -1}
it means that :
- arry[0] is equal to 1,
- arry[1] is equal to 3,
- arry[2] is equal to 5,
- and so on until 15.

But, you couldn't initialize these kind or array
  int arry[15] = {0, 0, 0, 0}
Why?
Because the integer arry only choose one data that is same.

In array you could even make an Assigning Value for Example :
- A[1] = 25; B[3] = 20
- C[6] = A[1] - B[3]
That means C[6] is 25 - 20 = 5.

So... That's all about Array.... Then how about Pointer ??



What is Pointer ??
Pointer is a variable that store the address of another variable or pointer is used to access the memory and manipulate the address.

The Syntax of Pointer 
- <type> *ptr_name;
- pointer uses mostly 2 type of operators which is : *(content of), &(address of)

The Example to use Pointer
- int *p; or int* p;
It means the variable p is the holder of the address and the asterisk is the content of
So that means " pointer p is a content of int " (the address name).

Initialize Pointer in C++

int point = 10;
int *pointr;
pointr = &point;
printf("%d", *pointr);

The output will be like this 

10

How ??
To make it sentence = " There is integer point and pointr, we give Pointer to integer pointr, And then we will read that pointr is address of point. "

Then we will print the result of *pointr going to point as a address.

The Simple example : pointr > point > bring up point value.


So... That's all about Pointer... 
Yeah I know that's more simple than Array but I hope that you (the one who reads) understand about 
Array & Pointer !!!

Thanks for Reading this Blog and Learn from this, I hope you like it  <3<3




Reference : 
- https://www.programiz.com/cpp-programming/pointers
- https://www.programiz.com/cpp-programming/arrays
- Paul Deitel & Harvey Deitel. (2016). C how to program : with an introduction to C++. 08. Pearson  Education. Hoboken. ISBN: 9780133976892. Chapter 6 & 7

Tidak ada komentar:

Posting Komentar