Rabu, 11 Maret 2020

C++ Tutorial: Array and DAAM operation

Hello, welcome to CPP tutorial.

In this tutorial we will discuss about Array and DAAM (Declare, Assign, Access and Modify) operation.

Array is fixed size and same type elements that collected together by the programmer. For instance, you can collected together few integer values, you can collected together few characters values or you can collected together some float values, etc. into a variable.

So, first we need to know how to declare an array?

Declare - How to declare an array?
First you need to think about the type of the data of each of element that you like and how many element that will be prepared for you.

The syntax is this:
data-type array's_name [array_size]

For example:
int height[5] = [12, 13, 40, 15, 56];
int float[3] = [13


Assign - How to assign element's value?
There are two ways of how to assign element's value are (you put curly braces when assigning value to each element using both methods):
1. Explicit
For example:
int height[5]={177,180,160,170,172};

2. Implicit
For example:
int height[]={177,180,160,170,172}

Accessing - How to access element's value?
You need to know the element index which you like to access and put the number (the element index) inside the square brackets. For example:
cout << height[1], or
cout << height[2].

You can also access the value of each array's element by using the pointer for instance:
int *p = height;
cout << "The value of height[" << i << "]: " << *p;

Modify - How to modify or change the element's value?
You can change any initiated elements of array using below commands:
height[1] = 12;

Thats it folks, I hope you like it.


You see,

Tidak ada komentar:

Posting Komentar