Passing an array structure as an array

I am unable to pass an array of a structure as a parameter to a function

struct Estructure{
 int a;
 int b;
};

      

and functions

Begining(Estructure &s1[])
{
   //modifi the estructure s1
};

      

and the main thing will be something like this

int main()
{
  Estructure m[200];
  Begining(m);
};

      

It's right?

+2


a source to share


5 answers


Begining(struct Estructure s1[])
{
   //modifi the estructure s1
};

int main()
{
  struct Estructure m[200];
  Begining(m);
  return 0;
};

      



0


a source


No, you need to print your structure and you must pass an array; pass by reference does not work in C.

typedef struct Estructure{
 int a;
 int b;
} Estructure_s;

Begining(Estructure_s s1[])
{
   //modify the estructure s1
}

int main()
{
  Estructure_s m[200];
  Begining(m);
}

      



As an alternative:

struct Estructure{
 int a;
 int b;
};

Begining(struct Estructure *s1)
{
   //modify the estructure s1
}

int main()
{
  struct Estructure m[200];
  Begining(m);
}

      

+1


a source


typedef struct {int a; int b;} Structure;

void Begining (Estructure * svector) {svector [0] .a = 1; }

0


a source


typedef struct{
 int a;
 int b;
} Estructure;

void Begining(Estructure s1[], int length)
//Begining(Estructure *s1)  //both are same
{
   //modify the estructure s1
};

int main()
{
  Estructure m[200];
  Begining(m, 200);
  return 0;
};

      

Note. Better to add length

to your function Beginning

.

0


a source


Either put the work structure in front of the Estructure or print it in some other type and use that. Also pass by reference doesn't exist in C, then pass the pointer if you like. Maybe:


void Begining(struct Estructure **s1)
{
   s1[1]->a = 0;
}

      

Not exactly the same as an array, but this should work in C land and it passes a pointer to efficiency.

0


a source







All Articles