Structural variables can be passed in their entirety as function parameters. Transfer process: All members are transferred one by one. Pointer variables are passed as function parameters. Then only the address is passed from the actual parameter to the formal parameter, thereby reducing the time and space overhead.
Programming using structure pointer variables as function parameters.
#include #define STU struct stu void ave(struct stu *ps); STU //stu structure name { int num; char *name; char sex; float score; }boy[5]={ {101,"Zhou ping",'M',45}, {102,"Zhang ping",'M',62.5}, {103,"Liou fang",'F',92.5}, {104,"Cheng ling",'F',87}, {105,"Wang ming",'M',58}, }; //boy[5] is a structure array, which is of type stu. Assign an initial value to the structure array. int main() { struct stu *ps; //ps structure pointer variable points to the first address of the boy[] structure array. ps=boy; ave(ps); //ps is used as an actual parameter to call the function ave to complete the calculation. } void ave(struct stu *ps) { int c=0,i; float ave,s=0; //s total score, ave average score for(i=0;i<5;i++,ps++) //ps++ cannot be dropped, otherwise it will loop 5 times in boy[1]. { s+=ps->score; if(ps->score<60) c+=1; //cThe number of people who failed } printf("s=%fn",s); ave=s/5; printf("average=%fncount=%dn",ave,c); } The formal parameter is the pointer variable ps, boy is defined as an external structure array, and the entire source program is valid.
Previous article:What should I do if the microcontroller clock is inaccurate? Adjust this way!
Next article:7 common interface types in circuit design
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- FPGA Deep Analysis.pdf
- C51 uses macro definition to replace printf function
- Understanding the CAN bus from the bottom up
- STM32F429 USB_OTG_FS (PA11, PA12) read USB disk problem
- Disassembling the USB wireless network card, the circuit scheme is very classic
- Low-cost MCU options
- 5G millimeter wave antenna
- Design of Switching Power Supply Using MSP430 Microcontroller
- About SPI mode setting
- LCD screen problem