当你在c中声明一个静态变量时

when you declare a static variable in c

当您在 C 中声明静态变量时,

假设你写了这样一个程序:

int *c;
void foo(){
    c = (int *) malloc (10*sizeof(int));
    c = &c[3];
    *c = *&c[3];
}

拥有*c是什么意思?我的意思是我明白 * 意味着它指向某物但是 *c 做什么?

另外,为什么需要将 (int *) 转换为 malloc() 的 return 值?

when you are declaring static variables in C

与这个问题无关,或者至少与您显示的代码无关。

but what does *c do?

假设您的问题与语句 *c = *&c[3]; 相关,它指的是 c.

持有的位于地址 的 对象

why did you have to cast (int *) in front of malloc?

你不应该。请 do not cast malloc() [和家人] 的 return 值。

注意:您的代码片段非常糟糕且实践不佳,很可能无效。 c = &c[3]; 明显的内存泄漏。

I mean I understand that * means that it points to something but what does *c do?

* 并不总是表示它指向某物。 例子: 如果你这样写:

int* c;

表示c是一个指向int变量的指针

当您这样做时:

int* c = &x;
*c = 5;

第二个*是指针cdereference.