【发布时间】:2018-01-22 04:12:15
【问题描述】:
我正在阅读一本名为 head first c 的书,他们告诉我一个关于投射指针的概念。我明白我为什么要这样做,但我想知道的是怎么做?比如语法是什么?
int compare_names(const void* a, const void* b)
{
const char** sa = (const char**)a;
const char** sb = (const char**)b;
//why would, in the return section, we use normal pointers instead of **?
return strcmp(*sa, *sb);
}
我知道在左侧我们使用了 2 个星号,因为 sa/sb 是指向指针的指针,但在右侧,我完全不知道发生了什么。我们是在对指针进行赋值吗?
还请解释一下关于退货线路的一切。
**One final question I have is when I write the a statement like (char*)a or (int*)a am I making "a" into an integer or a char?**
【问题讨论】:
-
现在是查看list of great references on C programming 的好时机。