Assigning Values to Structs

Structs are assigned to Structs either by reference or by value.

Structs are assigned by reference when the target (to the left of the = sign) is a variable or parameter.

Structs are assigned by value when the target is a Struct member.

Assignment by Reference

The following code assigns the Struct referenced by struct component variable vInputStruct to a local variable vBook:

  any vBook
; $vInputStruct$ is a struct component variable that refers to an existing Struct
vBook = $vInputStruct$

Now, both vBook and $vInputStruct$ refer to the same Struct. The Struct itself is not affected.

Assignment by Value

The following code assigns a value to the title member of the Struct referenced by vStruct:

vStruct->title = "Installation Guide"

The following code assigns the Struct referenced by vChapter to a Struct member named preface.

vStructMember->preface = vChapter

In this case, the contents of vChapter replace the preface member.

Related Topics