Pointer initialization issue

Hello @Syed_Karim,
In your task, you have provided, I can see 2 issues:
Firstly, lets take a look on your variable and pointer declarations:

CommVarOD : ARRAY[0..2] OF CommVarODType;
pODCommVar : REFERENCE TO ARRAY[0..2] OF CommVarODType;

First, on line 27, you need to use & to assign an address of CommVarOD to a ponter pODCommVar. It should look like this:
Line 27: pODCommVar = &CommVarOD;

Second, in your code, you use the pointer as “an array of pointers”.
Line 83: pODCommVar[i]->wSystemCommand = 194;
But your declaration and assignment are actually “pointer to an array”.
A way how to make your code work is, to dereference the pointer to the array and then accesses the element at the specified index. Here is corrected notation:
Line 83: (*pODCommVar)[i].wSystemCommand = 194;

By editing lines 27, 83, 89 and 94 according to provided examples, your code should work. :slight_smile:

2 Likes