- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to pass the address of structure as an argument to function in C language?
Passing the address of structure as an argument to function −
The Address of the structure is passed as an argument to the function.
It is collected in a pointer to structure in function header.
Advantages
No wastage of memory as there is no need of creating a copy again
No need of returning the values back as the function can access indirectly the entire structure and work on it.
Example
#include<stdio.h> struct date{ int day; int mon; int yr; }; main (){ struct date d= {02,01,2010}; display (&d); getch (); } display (struct date *dt){ printf("day = %d
", dt->day); printf("month = %d
",dt->mon); printf("Year = %d",dt->yr); }
Output
day = 2 month = 1 Year = 2010
Advertisements