> 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/principle-c-c++-programming/1.-arguments/command-line-arguments-in-c-and-c++.md).

# 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
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/principle-c-c++-programming/1.-arguments/command-line-arguments-in-c-and-c++.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.
