
In the above program, three structure variables c1, c2 and the address of result is passed to the addNumbers() function. Void addNumbers(complex c1, complex c2, complex *result) Printf("result.imag = %.1f", result.imag) Printf("\nresult.real = %.1f\n", result.real) We suggest you to read pass by reference tutorial before you proceed.ĭuring pass by reference, the memory addresses of struct variables are passed to the function. You can also pass structs by reference (in a similar way like you pass variables of built-in type by reference). Notice that, the return type of getInformation() is also struct student. The returned structure is displayed from the main() function. The function returns a structure of type struct student.

Here, the getInformation() function is called using s = getInformation() statement.

Here's how you can return structure from a function: #include

The variable is passed to the display() function using display(s1) statement. Here, a struct variable s1 of type struct student is created. read string input from the user until \n is enteredĭisplay(s1) // passing struct as an argument Here's how you can pass structures to a function #include We recommended you to learn these tutorials before you learn how to pass structs to functions. Similar to variables of built-in types, you can also pass structure variables to a function.
