I am relatively new to C ++ (about a year of experience, on and off). I am wondering what led to the solution type * nameas a syntax for defining pointers. It seems to me that the syntax should be type & name, since the character is &used everywhere in the code to refer to the address of the memory variable. So, to use a traditional example of pointers int:
type * name
type & name
&
int
int a = 1; int * b = &a;
will become
int a = 1; int & b = &a
I am sure that there are some reasons for this that I simply don’t see, and I would like to hear some materials from C ++ veterans.
Thanks, -S
++ C. "" C" (Dennis Ritchie) C * , .
*
[ ] : , , [ *] . , , . ,int i, *pi, **ppi; , , . , i, * pi ** ppi int .
[ ] : , , [ *] . , , . ,
int i, *pi, **ppi;
, , . , i, * pi ** ppi int .
:
int *(*foo)[4][];
, *(*foo)[4][0] int, ( [] , *), : foo - 4 ints.
*(*foo)[4][0]
[]
++ C. , , ++ .
int & b = a;
, int. , , , , , .
int x = 5, y = 10; int& r = x; int sum = r + y; // you do not need to say '*r' automatically dereferenced. r = y; // WRONG, 'r' can only have one thing pointing at during its life, only at its infancy ;)
, C:
, : index , , . , . ,int i, *pi, **ppi; , integer, . i, * pi ** ppi int . ,int f(), *f(), (*f)(); , integer, , , ;int *api[10], (*pai)[10]; . , , .
, : index , , . , . ,
, integer, . i, * pi ** ppi int . ,
int f(), *f(), (*f)();
, integer, , , ;
int *api[10], (*pai)[10];
. , , .
, type * var , () .
type * var
, "NB", "B", int pointer[] int, int array[10], int s.
int pointer[]
int array[10]
, , . , .
- , , , , .
, , ++ , . - , C , .
, ++, , . & someVariable, , , someVariable. , !
, Apple Objective-C , int *someIntPointer int* someIntPointer
int *someIntPointer
int* someIntPointer
IMHO, - C, , .
someIntPointer , . , , , :
someIntPointer
int* a, b; // b is a straight int, was that our intention? int *a, *b; // old-style C declaring two pointers int* a; int* b; // b is another pointer to an int
, , , , , .
C-, ++. , , - .
'&' . , .
"*" --. , .
, . .
int* b "b int", int *b: "* b - int". & anti- *: * b - int. *b - &*b b.
int* b
int *b
*b
&*b
, " K & R".
. , .
K & Rs are those who decided that the C syntax for declaring pointers was.
It is not int and x; instead of int * x; because the language that defines the guys who created it is K & R.