Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing pointers in C

Tags:

c

pointers

I see two option to assign a pointer

1.

int p=5;
int *r=&p

2.

int p
int *r;
r=&p;

Why do they use in 1 with asterisk and in two without?

like image 973
user1758424 Avatar asked Dec 06 '25 09:12

user1758424


1 Answers

You should read this:

int *r [...]

as:

(int *) r [...]

The type of r is int *. If you look at it that way, you'll see that both versions are identical.

like image 64
Mat Avatar answered Dec 08 '25 21:12

Mat