Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difficulty in understanding c pointers when it is on it's own

Tags:

c

pointers

I am studying pointers for c and this placement of * really really confuses me.

I understand what int *a is..

But what is

a = malloc(n * sizeof(int) ) 

I understand what above is doing but why is * in the middle of by itself?? This part really confuse me so please someone can explain to me?

like image 576
user3502374 Avatar asked Dec 12 '22 00:12

user3502374


2 Answers

unary * means dereferencing and binary * means multiplication.

like image 107
Jason Hu Avatar answered Jan 18 '23 22:01

Jason Hu


The * in the middle is a multiplicative operator. The result of the binary * operator is the product of the operands.
Do not confuse it with unary dereference operator which applies only on pointer objects.

like image 40
haccks Avatar answered Jan 18 '23 22:01

haccks