Hi Jerome,
1,I revised as below,now all the 7 lines of PrintLn prints 71492.
//************************
int planetRadii[Planet];
int* pointer=null;
planetsRadii[jupiter]=71492;
PrintLn("the fifth element of planetsRadii using pointer is
",pointer[Planet::jupiter]);
PrintLn("the fifth elements of planetsRadii using & is
",&pointer[Planet::jupiter]);
PrintLn("the fifth elements of planetsRadii using & with array
Name is",
&planetsRadii[4]);
PrintLn("The fifth elements of planetsRadii using & with array
Name and enum index is",
&planetsRadii[Planet::jupiter]);
PrintLn("The fifth elements of planetsRadii is
",planetsRadii[4]);
PrintLn("the fifth element of planetsRadii is ",pointer[4]);
PrintLn("the fifth element of planetsRadii is ",*(pointer
+4));
//****************************************
2.As we have discussed in previous thread,that a struct passed in the
function with a struct key word will make the struct parm passed by
value other than by reference.Say,
//*****************
struct InventoryItem
{
int code;
float price;
} ;
void print(InventoryItem item)
{
PrintLn("item.code= %d\nitem.price=%.2f\n",item.code,item.price);
}
void DontModifyItem(struct InventoryItem item)
{
item.code=1234;
item.price=45.0f;
}
void Test()
{
InventoryItem item1{};
DontModifyItem(item1);
Print(item1);
//***********************
This can not pass the compiler:
structApp.ec:17: error: invalid type argument of '->' (have 'struct
InventoryItem')
structApp.ec:18: error: invalid type argument of '->' (have 'struct
InventoryItem')
structApp.ec:23: error: incompatible type for argument 1 of
'DontModifyItem'
Hope this problem can be fixed very soon.
Regards,
Sam