Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the difference between python higher order functions and C language function pointers?

Shulou Source: shulou.com Published: 2022-06-02 12:04:12 09月28日 Update

This article mainly explains "what is the difference between python higher-order functions and C language function pointers". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what's the difference between python higher-order functions and C language function pointers?"

Python higher-order function: pass a function as an argument.

C language function pointer: pass in the function pointer as an argument, and the function pointer is also the basis of the polymorphic realization of C language.

We can see that they do have something in common. Let's take a look at the code of the two to accomplish the same function.

Python:

Def sub (aformab):

Return a Murb

Def test (a _

Return c (afort b)

A=test (2, 1, 1, sub)

Print (a)

C:

# include

Typedef int (* f) (int, int)

Int sub (int a pencil int b)

{

Return a Murb

}

Int test (int a _ line int b _ r f c)

{

Return (* c) (aPerm b)

}

Int main (void)

{

Printf ("% d\ n", test (2)

}

In fact, the test function takes the sub function as an argument, and then the main function calls the test function to complete a subtraction.

At this point, I believe you have a deeper understanding of "what is the difference between python higher-order functions and C language function pointers". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Functions pointers languages high-order same content practical learning polymorphic practical deeper code interest subtraction functions parameters fundamentals practicality in fact easy to operate Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL MariaDB OPPO Reno Docker