When using structs in functions, I have come along with two ways of passing them as arguments, and I don't know which one is better to use.
#include <stdio.h>
typedef struct Person{
int age;
int id;
} person;
static void foo(person *p1);
int main()
{
person per1;
person per2[1];
foo(&per1); /*1*/
foo(per2); /*2*/
printf("per1. Age: %i; id: %i\n",per1.age,per1.id);
printf("per2. Age: %i; id: %i\n",per2->age,per2->id);
return 0;
}
static void foo(person *p1)
{
p1->age=10;
p1->id=123;
}
The use case is for only one instance of the struct. If no more than one is needed, which one is better, in terms of performance and sense of usage, passing the address of the generic struct declaration, or passing a unitary array of the struct that will decay to a pointer?