带括号和不带括号的指针

时间:2014-02-24 04:03:50

标签: c pointers

第一: p = (int *)sp VS p = int *sp VS p = int (*sp)

第二: (struct node*) malloc(sizeof(struct node)) VS struct node* malloc(sizeof(struct node)) VS struct node (*malloc(sizeof(struct node)))

第三: #define cEEP_ABC *((CHAR *)ps8c_PROM( EEP_TEST+0x2B ))

第1和第2个问题中的陈述有何不同?

对于第3个问题,*((CHAR *)ps8c_PROM( EEP_TEST+0x564 ))

             ^      ^ 
             |      |
             |      |
             |      |
              ---------------- What the purpose for these 2 pointer?

声明是否可以更改为此表单:*(CHAR *ps8c_PROM( EEP_TEST+0x2B )) or *(CHAR (*ps8c_PROM( EEP_TEST+0x2B )))

1 个答案:

答案 0 :(得分:0)

<强>第一

p = (int *)sp; //typecasting sp to int* and storing it in p
p = int *sp; //Declares sp as int* and its value is stored in p
p = int (*sp); //Compilation error

<强>第二

(struct node*) malloc(sizeof(struct node)); //Allocates memory equal to size to struct node and returns a pointer to the start

Others: Compilation error.

<强>第三

(CHAR *)ps8c_PROM( EEP_TEST+0x564 )将函数的返回值强制转换为char *,前导*给出该地址指向的值。所以它返回char