# Command line arguments in C and C++

ในการออกแบบโปรแกรมภาษา C มักจะมีการนำ argument เข้ามาใช้ สำหรับผู้เริ่มต้นเขียนโปรแกรม อาจสงสัยว่า argument คืออะไร จะอธิบายในคำอธิบายด้านล่าง

> argument คือ การกำหนดหรือรับค่าที่จะนำไปใช้งานในฟังก์ชัน

ดังนั้น การเขียนโปรแกรมภาษา C จะมีการกำหนดการใช้งาน argument จึงจะยกตัวอย่างจากฟังก์ชัน main() ในภาษา C ซึ่งอยู่ภายในไลบรารี่ standard ของภาษา โดยการใช้งานฟังก์ชัน main จะมี 2 ลักษณะ

* main() หรือ main(void) จะใช้งานฟังก์ชัน main แบบไม่มี argument
* main(int argc,char \*argv\[]) เป็นการใช้งานแบบกำหนด argument โดยมีการรับค่า argument 2 ตัวคือ
  * argc หรือ argument counter จะใช้นับจำนวนตัวแปรของ argument ตัวหลัง(argv) เหมือนนับจำนวนกล่องใส่ของที่รับเข้ามา
  * argv หรือ argument vector คือ ค่าที่รับเข้ามาเปรียบเสมือนของที่นำไปใส่ในกล่องเก็บของโดยกล่องเก็บของแต่ละใบมีหมายเลขของกล่องเก็บของอยู่ กล่องที่มีหมายเลขของกล่องเรียกว่า vector&#x20;

> อาจสับสน array กับ vector โดย array คือกล่องเก็บของได้เหมือนกัน แต่ไม่มีหมายเลขระบุ แต่ vector คือกล่องเก็บของที่มีหมายเลขระบุ


---

# Agent Instructions: 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:

```
GET https://docs.aic-eec.com/c-c++-for-embedded-programming/principle-c-c++-programming/1.-arguments/command-line-arguments-in-c-and-c++.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
