can functions return structures if so please five me example
yes, say you have a structure representing a complex number
-
typedef struct { /* complex number type */
-
float real; /* real component */
-
float imag; /* imaginary component */
-
} Complex;
-
you code add two complex numbers so
-
/* Function to add a pair of complex numbers, result = x + y */
-
Complex c_add(const Complex x, const Complex y)
-
{
-
return c_numb(x.real + y.real, x.imag + y.imag); /* function result */
-
}
-
the result being returned a structure Complex