# Variable length structures tutorial

Suppose the source text looked like this:

```
struct node_t
{
  long id;
  char *name;
  long nchild;                  // number of children
  long child[];                 // children
};

node_t n0 = { 0, "first",  2, { 1, 2 } };
node_t n1 = { 1, "second", 1, { 3 }    };
node_t n2 = { 2, "third",  1, { 4 }    };
node_t n3 = { 3, "fourth", 0,          };
node_t n4 = { 4, "fifth",  0,          };
      
```

Note that the length of the last field of the structure is not specified. In order to be able to create structures like this in a disassembly we must create a special kind of structure – a variable sized structure. A variable sized structure is created just as a normal structure is. The only difference is that the last member of the structure should be declared as an array with zero elements. (Just a reminder: arrays are declared with an \* hotkey). Here is a sample variable sized structure definition:

![](/files/vip9qRNa4mch3M8T3fPl)

Now we may switch to the disassembly window (or just close the enumeration window by pressing Alt-F3). In order to apply the defined structure we use **Edit|Structs|Declare struct var**. But since the structure size cannot be calculated by IDA we need to specify the desired structure size by selecting an area to convert to a structure. Another way to specify the size of a structure would be to use \* hotkey. In all cases you need to tell IDA the exact size of a variable sized structure. The initial disassembly will evolve from this to this:

![](/files/f3x1DQ5VXCcW9sPIPxri)

![](/files/kFm6tb6HpHosIbLkhjU2)

That’s all folks !


---

# 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.hex-rays.com/9.0/user-guide/disassembler/varstr-tutorial.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.
