---
title: "Sending structure members to a function"
subject: "Computer Programming"
chapter: 8
key: "semester_1/computer_programming:structure-members-to-function"
source: https://www.bctengineer.com/q/semester_1/computer_programming/structure-members-to-function
site: BCT Engineering
---

# Sending structure members to a function

Computer Programming · Chapter 8: Structures

- Asked in: 2071 Shrawan, 4 marks
- Video: [C Programming Tutorial - 69: Passing Structures to Functions](https://www.youtube.com/watch?v=3WPQGVAmZvI) — The Bad Tutorials
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/structure-members-to-function
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-8

## Question

Write the program "to understand how structure members are sent to a function".

## Short answer

Structure members are passed to functions like ordinary variables: non-array members by value, character arrays by address. e.g., showMarks(s.marks) passes a copy of the float member, while showName(s.name) passes the address of the string.

## Answer

A member of a structure is an ordinary variable, so it can be sent to a function just like any other variable by writing `structure_variable.member` in the call.
- A member of a basic type (`int`, `float`, `char`) is sent **by value**: the function gets a copy, and the original does not change.
- A character array member (`s.name`) is sent as an array, so its address is passed (the function can change it).
- The type of the parameter must match the type of the member.

```c
#include <stdio.h>

struct student {
    char name[20];
    int roll;
    float marks;
};

/* a single member is sent: passed by value */
void showMarks(float m)
{
    printf("Marks received in function = %.1f\n", m);
}

/* name member is a character array: its address is sent */
void showName(char n[])
{
    printf("Name received in function  = %s\n", n);
}

int main(void)
{
    struct student s = {"Ram", 10, 78.5};
    showMarks(s.marks);       /* member sent as argument */
    showName(s.name);
    showMarks(s.roll);        /* int converted to float */
    return 0;
}
```

**Output**

```text
Marks received in function = 78.5
Name received in function  = Ram
Marks received in function = 10.0
```

`s.marks` (float) and `s.name` (char array) were sent to separate functions. In the last call the `int` member `s.roll` is converted to `float` by the compiler.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How is a structure member sent to a function?
   A. Write only the member name
   B. Write structure_variable.member in the call
   C. Write &structure
   D. It cannot be sent
   Answer: B. A member is an ordinary variable. (Key point: Sending member)

2. How is a basic type member (int, float, char) passed?
   A. By address
   B. By reference always
   C. By value, so the original does not change
   D. It is not allowed
   Answer: C. The function receives a copy. (Key point: Basic type)

3. What is passed when s.name is sent?
   A. A copy of the string
   B. Only the first character
   C. Nothing
   D. The address of the array, so the function can change it
   Answer: D. Arrays are passed as addresses. (Key point: Character array)

4. What happens when int s.roll is passed to float parameter?
   A. It is converted to float by the compiler
   B. Compile error always
   C. It is printed as garbage
   D. The program stops
   Answer: A. The output shows 10.0. (Key point: Type match)

## Related in Computer Programming

- [Structure of a FORTRAN program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-structure) — Computer Programming, chapter 11, asked 5×
- [Declaration vs definition; C program structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adeclaration-definition-structure-of-c) — Computer Programming, chapter 3
- [Structure vs array; accessing members](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astructure-vs-array-access-members) — Computer Programming, chapter 8
- [Height difference using nested structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-height-feet-inches) — Computer Programming, chapter 8
- [College records with nested date structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-college-estdate) — Computer Programming, chapter 8
- [Complex number multiplication using structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-complex-multiply) — Computer Programming, chapter 8

## Related in other subjects

- [Program using static members](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Astatic-program) — Object Oriented Programming, chapter 4
- [Function overloading; new/delete average program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afunction-overloading-new-delete-average) — Object Oriented Programming, chapter 3
- [Access overridden members from derived class](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aaccess-overridden-members) — Object Oriented Programming, chapter 6, asked 2×
- [Protected specifier; student/test/result program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprotected-three-class-program) — Object Oriented Programming, chapter 6
