> For the complete documentation index, see [llms.txt](https://docs.aic-eec.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aic-eec.com/c-c++-for-embedded-programming/c-programming-techniques/array-and-properties-of-an-array.md).

# Array and properties of an array

Array คืออะไร\
&#x20;        อาร์เรย์เป็นประเภทหนึ่งในการจัดเก็บตัวแปร โดยอาร์เรย์จะสามารถเก็บค่าได้หลายๆค่าต่างกับตัวแปรธรรมดาที่สามารถเก็บค่าได้ทีละ1ค่า

![](/files/-MRyO21LG00AjE3DcLe6)

โดยการประกาศอาร์เรย์นั้นสามารถทำได้โดยการใช้คำสั่งดังนี้

```cpp
// ประเภท ชื่อ[ขนาด]; เช่น
int Hallway[9];
string cars[5];
double grade[4] = {4.00,3.79,2.75,3.11};
char Alpgrade[5] = {'A','B','C','D','F'};
string name[] = {"Jame","Jack","John"};
```

จากตัวอย่างด้านบนจะเห็นได้ว่า เราสามารถประกาศอาร์เรย์สำหรับเก็บค่าต่างเหมือนกับการประกาศตัวแปรปกติ แต่มีสิ่งที่เพิ่มเติมมาคือ \[ขนาด] ที่ต้องใส่ต่อท้าย ซึ่งขนาดของอาร์เรย์นั้นไม่จำเป็นต้องระบุก็ได้ เช่นเดียวกับในตัวอย่างบรรทัดที่6 ซึ่งในบรรทัดที่ 6 นั้นจะมีขนาดของอาเรย์คือ 3 ช่องตามข้อมูลที่กำหนดไว้ให้นั่นเอง

ตัวอย่างการใช้งานอาร์เรย์

```cpp
#include <iostream> 
using namespace std; 

// index example code 
int main() 
{ int allnumber[5] = {4,11,76,4,88};
  cout << allnumber[0] << endl;
  cout << allnumber[1] << endl;
  cout << allnumber[2] << endl;
  cout << allnumber[3] << endl;
  cout << allnumber[4] << endl;
  cout << allnumber << endl;
    return 0; 
} 
```

{% hint style="info" %}
จากตัวอย่างด้านบนจะเห็นว่า Array จะเริ่มต้นช่องแรกด้วยการนับที่ index ที่ \[0]
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.aic-eec.com/c-c++-for-embedded-programming/c-programming-techniques/array-and-properties-of-an-array.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
