Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 圆括号内的指针_C_Pointers_Brackets - Fatal编程技术网

C 圆括号内的指针

C 圆括号内的指针,c,pointers,brackets,C,Pointers,Brackets,如果我没记错的话,在指针上加括号意味着调用函数? 如果这是真的,我真的不明白为什么*head\u ref上有括号。 我想解释一下为什么我需要在这段代码中的*head\u ref上加括号。在这种特殊情况下,括号除了澄清程序员的意图之外,没有其他用途,也就是说,他们想取消引用head\u ref 请注意,head\u ref是指向指针的指针,因此在这种情况下,new\u node->next被设置为指向链接列表的原始头,然后head\u ref指向的指针被更新为指向new\u node,现在是列表的

如果我没记错的话,在指针上加括号意味着调用函数? 如果这是真的,我真的不明白为什么*head\u ref上有括号。
我想解释一下为什么我需要在这段代码中的
*head\u ref
上加括号。

在这种特殊情况下,括号除了澄清程序员的意图之外,没有其他用途,也就是说,他们想取消引用
head\u ref

请注意,
head\u ref
是指向指针的指针,因此在这种情况下,
new\u node->next
被设置为指向链接列表的原始头,然后
head\u ref
指向的指针被更新为指向
new\u node
,现在是列表的开始


正如MichaelKrelin在下面指出的,在指针周围加括号并不意味着它是调用函数或指向函数的指针。如果您看到:
(*head\u ref)(
,那么它将调用
head\u ref
所指向的函数

调用函数将类似于:

void push(struct node** head_ref, int new_data)
{
    /* allocate node */
    struct node* new_node =
            (struct node*) malloc(sizeof(struct node));

    /* put in the data  */
    new_node->data  = new_data;

    /* link the old list off the new node */
    new_node->next = (*head_ref);   

    /* move the head to point to the new node */
    (*head_ref)    = new_node;
}
你案例中的括号没有意义


此外,无需在C中强制转换
malloc
void*
)的结果。

在您的案例中,只需取消对此处指针的引用即可

您所说的:“在指针上加括号意味着调用函数”

如果*后面的是函数指针,则为true。
基本上它取决于指针的类型。

这些括号仅用于分组

要通过指向函数的指针调用函数,请执行以下操作:

(*some_func_pointer)();
对于一个不带参数的函数,它应该是
()


您的示例在变量后面没有一对括号,因此它不是函数调用。

+1和否,指针周围的括号并不意味着调用函数。
(* funcPointer)(param1,param2)
^             ^^         ^
|             |`---------`--- These brackets tell the compiler 
|             |               it's a function call
|             |
`-------------`---------------These brackets just group the * 
                              with the variable name