> For the complete documentation index, see [llms.txt](https://applezulab.netdpi.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://applezulab.netdpi.net/linux-prog/c-pointer-and-array.md).

# \[C] Pointer and array

Here, we define a pointer named ptr to point to a memory block whose size is (1024\*sizeof(char)).

char \*ptr = malloc( sizeof(char) \* 1024);

The value of sizeof(ptr) is the size of ptr, and the value of sizeof(\*ptr) is the size of the first character in the memory block pointed by ptr.

If we define an array whose size is 1024 characters:

char array\[1024];

The value of sizeof(array) is (1024 \* sizeof(char)).

However, sizeof(\*array) is sizeof(char).

Because \*array means \*(array+0) which is equivalent to array\[0], we get the size of the first item in array.

For example, array\[2] = \*(array+2) = \*(2+array) = 2\[array]

We use memset(array, 0, sizeof(array)) to clean the array.

However, if we want to clean the memory pointed by ptr, we have to record the size of the memory ourselves.

For example, we use buf\_size to record the size of memory pointed by ptr.

buf\_size = ( sizeof(char) \* 1024 ); ptr = malloc(buf\_size); memset(ptr, 0, buf\_size);


---

# 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://applezulab.netdpi.net/linux-prog/c-pointer-and-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.
