What does this C pointer code do?

I just came up with this code at 1:06 minute from a lecture cursor . What is he doing?

int (*cmp)(char*, char*);
+4
source share
3 answers

This is a pointer to a function in which the function returns int and takes two pointers to characters as an argument.


The basic rule comes down to a few things: -

There are three simple steps:

  • Starting from an unknown element, move in a spiral / clockwise direction; When replacing the following items, replace them with the appropriate English instructions:[X] or []
    • Array Xsize ... or array undefined size ...(type1, type2)
    • transfer function type1and type2returns ... *
    • ... / , . - !

: 1. 2.

+10

C, butrophedonically ( ).

pointer to
  function that 
    has (char*, char*) type parameters as input
    and int as output

EDIT:

+6

, , . prototype :  int cmp (char*, char*);

: - , - cmp, , (). , , , , , , , , . , :

char c1 = 'a';
char c2 = 'b';
int result = cmp(&c1, &c2);

, . -1, 'a' , 'b'. , - / . & - .

, , * cmp. , , - . , qsort C:

void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*))

, . , , qsort, .

C.

, .

+1

Source: https://habr.com/ru/post/1688345/


All Articles