1) You can create an array of links.

2) Pointers may be uninitialized.

3) Pointers can be subtracted.

4) Pointers can be multiplied by an integer.

5) Pointers can be added to each other.

6) Links may be uninitialized.

7) You can not get the address of the link.

Closed due to the fact that Nicolas Chabanovsky, a member of the question ♦ December 5 '16 at 5:24 , is incomprehensible.

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 3
    And you try it in practice :) Seriously, what you yourself will do - you will remember for a long time ... - Harry
  • @Harry and what to try? Here, for example, point 5 will be compiled and will work, but can they be added or not according to the standard? - pavel
  • 2
    @pavel, if the 5th is compiled, then you need to update the compiler :) - ixSci
  • @ixSci my borland compiles) - pavel
  • 2
    @pavel, borland still not burning in Hell? - ixSci

2 answers 2

int main() { // 1 int& x1[5]; // 2 int * x2; // 3 int *x3, *x4; auto dx = x3 - x4; // 4 int *x5 = x3*5; // 5 auto x6 = x3 + x4; // 6 int& z; // 7 auto y = &z; } 

VC ++ 2015:

 test.cpp(6): error C2234: x1: нСдопустимый массив ссылок test.cpp(16): error C2296: *: нСдопустимо, Π»Π΅Π²Ρ‹ΠΉ ΠΎΠΏΠ΅Ρ€Π°Π½Π΄ ΠΈΠΌΠ΅Π΅Ρ‚ Ρ‚ΠΈΠΏ "int *" test.cpp(19): error C2110: +: Π½Π΅Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Π΄Π²Π° указатСля test.cpp(22): error C2530: z: ссылки Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Ρ‹ 

GCC :

 prog.cpp: In function 'int main()': prog.cpp:4:14: error: declaration of 'x1' as array of references int& x1[5]; ^ prog.cpp:14:18: error: invalid operands of types 'int*' and 'int' to binary 'operator*' int *x5 = x3*5; ^ prog.cpp:17:20: error: invalid operands of types 'int*' and 'int*' to binary 'operator+' auto x6 = x3 + x4; ^ prog.cpp:20:10: error: 'z' declared as reference but not initialized int& z; ^ 

Clang 3.7 :

 prog.cpp:4:12: error: 'x1' declared as array of references of type 'int &' int& x1[5]; ^ prog.cpp:11:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions] auto dx = x3 - x4; ^ prog.cpp:14:17: error: invalid operands to binary expression ('int *' and 'int') int *x5 = x3*5; ~~^~ prog.cpp:17:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions] auto x6 = x3 + x4; ^ prog.cpp:17:18: error: invalid operands to binary expression ('int *' and 'int *') auto x6 = x3 + x4; ~~ ^ ~~ prog.cpp:20:10: error: declaration of reference variable 'z' requires an initializer int& z; ^ prog.cpp:23:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions] auto y = &z; ^ 3 warnings and 4 errors generated. 
  • 7 is not correct, you get the address of a variable of type int , and not links. - ixSci
  • @ixSci And how can you get it at all? :) Formally , z is the link, &z is the address of the link :) What else can you do? - Harry
  • I believe that in any way. A link in C ++ is a very interesting entity, as if it is, and as if it is not :). - ixSci
  • @Harry, therefore, I said that to run a little, you need to understand what else to run) and if you understand this, you can do without starting. - pavel
  • one
    @pavel What I wrote should be understood as necessary, but not a sufficient condition ... - Harry

1) You can create an array of links.

According to the C ++ standard (8.3.4 Arrays)

  1. ... T is called the array element type; This is a void, a function type or an abstract class.

That is, array elements cannot be references, or have type void (but can be pointers to type Void), cannot have type of functions (but can be pointers to functions) and cannot be objects of an abstract class.

2) Pointers may be uninitialized.

If the pointer is not constant, then it may not be initialized.

3) Pointers can be subtracted

From standard C ++ (5.7 Additive operators)

2 For subtraction, one of the following

- both operands have arithmetic or unscoped enumeration type; or

- both operands are pointers to the same fully defined object type ; or

It is a rule of reference to a completely undefined object type.

And there

If you’re on the top of the line up

That is, when two pointers address elements of the same array, their difference is equal to the difference between the indices of the addressed elements of the array.

4) Pointers can be multiplied by an integer.

The C ++ standard section "5.6 Multiplicative operators" states that

2 The operands of arithmetic or unscale enumeration type;

For pointers, the multiplication operation is not defined.

5) Pointers can be added to each other.

Returning to the C ++ standard section "5.7 Additive operators", we see that the addition operation is not defined for pointers

  1. ... In addition, either it can be an integral type or an enumeration type.

Do not add pointers.

6) Links may be uninitialized.

In the C ++ standard section "8.3.2 References" it is written that

  1. ... this is a class member (9.2) a parameter or a return type (8.3.5); see 3.1. 7)

That is, when a link is declared, the link must be initialized except when it is declared with the extern qualifier, is a member of the class, is a declaration within the class, or a function parameter declaration.

Cannot get link address

Links can be thought of as object names. When a reference is used, the operator takes the address & , then the address of the object to which the link "links" is returned. The address of the link itself cannot be obtained, since at least the standard does not specify whether the links require memory for themselves or not.