函数指针作为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? what is it doing?

好吧,我明白了一个将会转移到MyType *但是在那之后左边的那个明星怎么样?它在做什么?

Well, i guess this just dereference the pointer a?

好吧,我想这只是取消引用指针a?

thx.

谢谢。

/me

/我

1 个解决方案

#1


2  

Well i understand a will casted to MyType* but what about the star after that on the very left? what is it doing?

好吧,我明白了一个将会转移到MyType *但是在那之后左边的那个明星怎么样?它在做什么?

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是一个指针和指针保存一些有效的内存位置,通过使用*运算符获取存储在该内存位置的值,该运算符称为解引用指针


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2015/01/28/59f28bb24b9f310a8a106b2bf7d482c2.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号