
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
How to pass the individual members as arguments to function using structure elements?
There are three ways by which the values of structure can be transferred from one function to another. They are as follows −
- Passing individual members as arguments to function.
- Passing entire structure as an argument to function.
- Passing the address of structure as an argument to function.
Now let’s see how to pass an individual member of structure elements as arguments to function.
Each member is passed as an argument in the function call.
They are collected independently in ordinary variables in function header.
Example
Given below is a C program to demonstrate passing individual arguments of structure to a function −
#include<stdio.h> struct date{ int day; int mon; int yr; }; main ( ){ struct date d= {02,01,2010}; // struct date d; display(d.day, d.mon, d.yr);// passing individual mem as argument to function getch ( ); } display(int a, int b, int c){ printf("day = %d
", a); printf("month = %d
",b); printf("year = %d
",c); }
Output
When the above program is executed, it produces the following result −
day = 2 month = 1 year = 2010
Example 2
Consider another example, wherein, a C program to demonstrate passing individual arguments of structure to a function is explained below −
#include <stdio.h> #include <string.h> struct student{ int id; char name[20]; float percentage; char temp; }; struct student record; // Global declaration of structure int main(){ record.id=1; strcpy(record.name, "Raju"); record.percentage = 86.5; structure_demo(record.id,record.name,record.percentage); return 0; } void structure_demo(int id,char name[],float percentage){ printf(" Id is: %d
", id); printf(" Name is: %s
", name); printf(" Percentage is: %.2f
",percentage); }
Output
When the above program is executed, it produces the following result −
Id is: 1 Name is: Raju Percentage is: 86.5
- Related Articles
- How to pass individual members of structure as arguments to function in C language?
- How to pass individual elements in an array as argument to function in C language?
- How to pass arrays as function arguments in JavaScript?
- Python Program to pass the tuple as function arguments
- How to pass the address of structure as an argument to function in C?
- How to pass entire structure as an argument to function in C language?
- How to pass an entire structure as an argument to function in C?
- How to pass arguments by value in Python function?
- How to pass arguments by reference in Python function?
- How to pass the address of structure as an argument to function in C language?
- How to pass arguments by reference in a Python function?
- How to pass Python function as a function argument?
- Java Program to pass method call as arguments to another method
- How to pass arguments to animation.FuncAnimation() in Matplotlib?
- How to pass arguments to anonymous functions in JavaScript?

Advertisements