Why use * notation to define a pointer and dereference?

Is there a reason c developers used the star to determine the type of pointer

int* x;

and dereferencing a pointer?

int y = *x;

Using the same symbol for two different things seems confusing, especially since they are always used in the same context.

+4
source share
1 answer

There is an excellent answer to this topic in Quora from Brian Bee . I reproduce it here verbatim. http://www.quora.com/C-programming-language/Why-doesnt-C-use-better-notation-for-pointers

, , - - C. .

, . , , . , .

.

: int * a; * a int. , a int.

: int * a [10]; , * a [i] ( 0 9 ) int. , , , a - , [] (.. ), * on (.. )... int. , a [10] int.

int (* a) [10]; , (* a) [i] int. a - , * on, . [] int. , , a [10] int.

, ! , . , , , , . , , .

C , . , . , , strcpy. , , , (), , (), ; char, const char *. char *.

p. , , , * p. p char const char *, * p: (p) (char, const char *). ( p , .) , , char . , : char * (p) (char, const char *);

const - . const , , , , "". , .

, , , const char * s; . , const char, .. * s const char. char const * s;. , "" * s, const, , , const. const , char. , * s char, const, word const * s.

char * const s;? , const char. , , , . const s, " " , . s is const before it , * s const. char const * const s; const char * const s; const const char.

( ) . const char ** p; const char, char const ** p;. char * const * p; const char, char ** const p; delcares const char.

, , .

+6

Source: https://habr.com/ru/post/1534098/


All Articles