简体   繁体   English

函数指针作为qsort函数的参数

[英]Function pointer as parameter of qsort function

at the qsort function in c there is a functin pointer to the compare function, which actually sorts the data of the array given. 在c中的qsort函数中,有一个指向compare函数的functin指针,该指针实际上是对给定数组的数据进行排序。

so inside that function i see: 所以在该函数中,我看到:

if ( *(MyType*)a <  *(MyType*)b ) return -1;

Well i understand a will casted to MyType* but what about the star after that on the very left? 好吧,我知道将遗嘱强制转换为MyType *,但是之后那颗星星在最左边呢? what is it doing? 到底在做什么

Well, i guess this just dereference the pointer a? 好吧,我想这只是解引用指针了吗?

thx. 谢谢。

/me /我

Well i understand a will casted to MyType* but what about the star after that on the very left? 好吧,我知道将遗嘱强制转换为MyType *,但是之后那颗星星在最左边呢? what is it doing? 到底在做什么

So you know a is a pointer and pointer holds some valid memory location the value stored in that memory location is fetched by using the * operator which is called Dereferencing a pointer 因此,您知道a是一个指针,并且指针持有一些有效的内存位置,该存储在该内存位置中的值是通过使用*运算符(称为解引用指针)来获取的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM