小编Eve*_*ine的帖子

C: How do I correctly access an Array element of a Struct passed by reference?

I have this code:

typedef struct _structVar{
   int myArray[10];
} structVar;

structVar MyStruct;

Run Code Online (Sandbox Code Playgroud)

Then I'm passing the struct by reference to a function:

myFunct(&MyStruct);
Run Code Online (Sandbox Code Playgroud)

How I access array elements inside MyFunct?

void myFunct(structVar *iStruct){

   for(char i=0; i<10; i++)
      (*iStruct)->myArray[i] = i; //Fix Here
}
Run Code Online (Sandbox Code Playgroud)

Thanks for the help.

c arrays struct pointers member-access

-1
推荐指数
1
解决办法
60
查看次数

标签 统计

arrays ×1

c ×1

member-access ×1

pointers ×1

struct ×1