Zhou Ligong teaches you to learn C language programming and programming: this is best to write a function pointer array.

The second chapter focuses on programming technology. In this section, we’ll discuss function pointer arrays, specifically under subsection 2.1.4. Function pointer arrays are essentially arrays where each element holds the address of a function, enabling dynamic execution based on certain conditions.

Imagine you’re building a simple pocket calculator. After reading two numbers, op1 and op2, along with an operator, oper, you could use a series of if-else or switch-case statements to determine which operation to perform. For instance:

However, if your calculator supports hundreds of operations, such a switch-case structure would become cumbersome and difficult to manage. A more efficient approach is to utilize a transfer table, which is essentially an array of function pointers. Each element in this array points to a specific function. Consider the following example:

In this case, PF represents a pointer type to a function that returns a double and takes two double parameters. To store the addresses of four functions, you could declare an array variable named `oper_func` using PF:

Though the syntax may differ slightly, the meaning remains consistent. Assigning values to elements in a function pointer array is similar to assigning values to regular array elements. For instance:

To build a transfer table, you must declare and initialize an array of function pointers. Ensure that the function prototypes are declared before the array definition. Here’s an example:

This statement initializes four elements, eliminating the need for subsequent assignments. It’s crucial to ensure that the order of function names in the initialization list aligns with the integer codes used to represent each operator in your program. In this example, ADD, SUB, MUL, and DIV correspond to 0, 1, 2, and 3, respectively. The call format looks like this:

Here, the `oper` variable selects the appropriate function pointer from the array, and the function call operator executes the selected function. Alternatively, you can omit the size of the array and let the initialization list determine its size:

The initial values in the braces dictate the number of elements in the array, making the initialization list for a function pointer array identical to that of other arrays.

For additional resources, readers can reply to the keyword "[programming]" in our public account to access two books: “Programming for AMetal Framework and Interface (Top)” and “Programming and Data Structures.”

The book "Programming for AMetal Frameworks and Interfaces (I)" is currently in the printing phase and will be announced upon release. The Taobao purchase link for "Programming and Data Structures" is as follows, which can be copied into a browser to open:

https://s.click.taobao.com/d3WStbw

For further reading, here are some relevant topics:

Zhou Ligong: A Callback Function That Must Be Mastered in Software Module Layered Design

Zhou Ligong: Dynamically Distributed Memory – free() Function and realloc() Function

Zhou Ligong: Dynamically Distributed Memory – malloc() Function and calloc() Function

Zhou Ligong: Constructing a Double Pointer with an Array

Zhou Ligong: Do You Know That Arrays Can Also Save Pointers?

Zhou Ligong: The True Value of Characters Lies in the Formation of Character Sequences – String Functions

Zhou Ligong: The True Value of Characters Lies in the Formation of Character Sequences – Input and Output of Strings

Zhou Ligong: The True Value of Characters Lies in the Formation of Character Sequences – Reference to a String

Zhou Ligong: Characters Can Be Calculated Like Integers

Zhou Ligong: How to Pass a Two-Dimensional Array as a Function Parameter

Zhou Ligong: Generalization of Algorithms, You Should Know

Zhou Ligong: Generic Programming – Implementing Code Reuse

Zhou Ligong: Four Methods and Idioms for Array Access

Zhou Ligong: The Rules of the Array, Do You Know?

Zhou Ligong: C Language Array and Pointer Detailed Explanation

Zhou Ligong: Implementing and Using an Easy-to-Use Abstract Interface

Zhou Ligong: Five Things to Pay Attention to When Designing a Good Program Interface

Zhou Ligong: New Thinking and New Methods of Programming

Zhou Ligong: Splitting Conditional Statements Makes Code Easier to Understand – Comprehensive Expressions and Conditional Expressions

Zhou Ligong: Splitting Conditional Statements Makes Code Easier to Understand – Logical Expressions

Introduction to the Public Account:

Zhiyuan Electronics' official WeChat public account serves as a research and development testing sharing platform for 500 engineers, offering you leading product technologies and solutions in the electronics industry.

Agricultural Machinery Accessories Parts

Agricultural machinery parts more generally summarizes the machinery parts associated with agricultural production, the coverage is very wide. Such as: tractor power mechanical parts, tires, bucket, etc., harvester including potato harvester, peanut harvester, agricultural machinery and tools (pear. Take the plough as an example, the plough includes the disc plough, moldshare plough, animal force plough, the component of the whole machine includes the plow tip, the plow leg, the plow share, the plow piece and so on. Related industries, the production of supporting products accessories can be called agricultural machinery accessories.

What are common agricultural machinery accessoriesNow rural use of agricultural machinery is common, in the job, because of farmland environment is bad, so most of farm machinery accessories used are consumables, need to change regularly, in order to avoid failure, farm machinery accessories usually used are:1, agricultural tiresQualified agricultural tires tues both sides have the trademark, model, specification, layer number and the cord material etc, and clear, eye-catching, some still carries with production and inspection chapter; Inner surface should be smooth with brightness, the hand has the elasticity. If the tyre surface identification is not complete or fuzzy, inner tube lacklustre, tire body thin and uneven thickness, hand inelastic, is defective.2, threadProduct appearance should be bright and clean without rust, without defects, continuous spiral arm, no burr, no crack. Will be specimen and standard accessories spinning together, should be able to spin to the terminal, and no card lag phenomenon in the process of precession; Spin after flipping the fittings should be without shaking and sound, and if the thread has defects such as corrosion, crack, burr, spin the move after fitting will shake, for inferiority of quality.3, the gearQualified gear packing should be in good condition, tooth surface should be smooth and no cutting marks, no burr, and coated with anti-rust oil or wax, gear profile usually have code, with a hacksaw blade broken crop row gear face, should be no scratches or only a fine scratches. If the gear surface have burr, notching, rust, sharp strokes with sawdust and Nick (insufficient hardness), the poor quality.4, V beltQualified V belt surface is smooth, seamless joint glue, outside the circle on a clear trademark, specification, manufacturer name and logo, the length of the same type of V belt should be consistent.If the V belt look rough, uneven glue joint or openings, shade thrum exposed edges, no marks or blur, the V belt length is differ, it is false and inferior product.5, V belt wheelQualified V belt wheel surface porosity, crack, grooved smooth, V belt buckle grooved, V belt is slightly higher than that of slot and the bottom of the V belt is not drain contact. If discover wheel blowhole defects such as trough, the groove surface shape and qualified V belt do not form a complete set, it is bad.

Agricultural cnc machining,metal parts

Tianhui Machine Co.,Ltd , https://www.thcastings.com