how to pass a structure members to a function

hi
how to pass a structure members to a function.. and then initialize those members of a structure.. show an example by taking structure members as pointers.
thanks in advance
[195 byte] By [dineshchirayil] at [2007-11-20 10:29:42]
# 1 Re: how to pass a structure members to a function
struct Struct {
int a;
int b;
};
void Init(Struct* s)
{
s->a = 1;
s->b = 2;
}
int main()
{
Struct ss;
Init(&ss);
}
S_M_A at 2007-11-10 22:29:37 >
# 2 Re: how to pass a structure members to a function
struct Struct {
int a;
int b;
};
void Init(Struct* s)
{
s->a = 1;
s->b = 2;
}
int main()
{
Struct ss;
Init(&ss);
}

[almost] equivalently (for programmer "only" difference is, that you can't pass NULL through reference):
struct Struct {
int a;
int b;
};
void Init(Struct& s)
{
s.a = 1;
s.b = 2;
}
int main()
{
Struct ss;
Init(ss);
return 0;
}

sorry, what do you mean exactly by "taking structure members as pointers"?

this? :
struct Struct {
int* a;
int* b;
};

then you'd use something like:
void Init(Struct& s)
{
s.a = new int;
*s.a = 0;
s.b = new int;
*s.b = 0;
}
JustChecking at 2007-11-10 22:30:48 >