E
Elliot Marks
If a struct or its members are passed
to a function, must it be declared globally?
#include <stdio.h>
struct mystruct{
int a;
int b;
};
int structfunc(struct mystruct foo);
int main(void)
{
struct mystruct bar;
bar.a = 123;
bar.b = 456;
int sum = structfunc(bar);
printf("%d\n", sum);
return 0;
}
int structfunc(struct mystruct foo)
{
int sum = foo.a + foo.b;
return sum;
}
This code doesn't compile if the struct
declaration is moved inside main().
to a function, must it be declared globally?
#include <stdio.h>
struct mystruct{
int a;
int b;
};
int structfunc(struct mystruct foo);
int main(void)
{
struct mystruct bar;
bar.a = 123;
bar.b = 456;
int sum = structfunc(bar);
printf("%d\n", sum);
return 0;
}
int structfunc(struct mystruct foo)
{
int sum = foo.a + foo.b;
return sum;
}
This code doesn't compile if the struct
declaration is moved inside main().