When one alias uses two variables as
int a; const int &b = a;
the two variables are virtually the same, so any change applied to the variable aalso applies to the variable b. However, when the same trick is performed with pointers, it does not work as shown in the following program:
a
b
#include <iostream> int main(void) { int *a = (int*) 0x1; const int *const &b = a;// Now b should be an alias to a. a = (int*) 0x2;// This should change b to 0x2. std::cout << b << "\n";// Outputs 0x1 instead of the expected value of 0x2. return 0; }
Now a variable ais not an alias of a variable in the end b, but why?
const int *const & const const int. ( .) , const int *, int * (.. a). . const int *const &b = a; * ( const int *, a), ; a, b a.
const int *const &
const
const int
const int *
int *
const int *const &b = a;
. 1- const int; const , , (int * vs. const int *). const ( ), , .. int * const &.
int
int * const &
* b.
const int * const & b const int. int * const & b
const int * const & b
int * const & b
. https://cdecl.org/
Source: https://habr.com/ru/post/1691715/More articles:Regex to replace certain control characters, except for a few special cases of C #? - c #How to parse CSV with commas embedded in quotation marks? - c ++Completion of reaction. Semantic user interface with button and close icon - javascriptFind the consecutive number 1 - javaCordoba 8 + iOS 4.5.4 = cannot find the module "../cordova/platform_metadata" - iosCordoba cannot find module - androidRound corner text background like Instagram - iosSybase IQ download table using client file fails - sybaseJupyter notebook: TypeError: __init __ () received an unexpected keyword argument 'io_loop' - pythonWhat is the correct way: print "File size: $ st-> size" in perl? - perlAll Articles