What is the citation principle of C++?
This article mainly introduces "what is the principle of C++ citation". In daily operation, I believe many people have doubts about what the principle of C++ citation is. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "what is the citation principle of C++?" Next, please follow the editor to study!
1. Directly define the reference variable sample code # includevoid fun () {int a = 1; int& b = a; b = 10;} int main () {fun (); return 0 } Code disassembly result (using VS disassembly, just look at the code of the fun function) # includevoid fun () {00007FF7AAD01920 push rdi 00007FF7AAD01922 sub rsp,40h 00007FF7AAD01926 mov rdi,rsp 00007FF7AAD01929 mov ecx,10h 00007FF7AAD0192E mov eax,0CCCCCCCCh 00007FF7AAD01933 rep stos dword ptr [rdi] / / defines a pair of variables a with the address of rsp + 24 hours, initializing the contents of this address to 1 int a = 1 00007FF7AAD01935 mov dword ptr [rsp+24h], 1 / create the variable b is a reference to a, b is a pointer to a, the address of variable b is rsp+38h// lea rax, [rsp+24h] gets the address of variable an and puts the address in the rax register / / qword ptr [rsp+38h], and rax assigns the contents of rax to the variable b int& b = a 00007FF7AAD0193D lea rax, [rsp+24h] 00007FF7AAD01942 mov qword ptr [rsp+38h], rax / / when modifying the value of variable b, first get the contents of b into the register, and then take the contents of the register as the address Modify the data of the corresponding address / / mov rax,qword ptr [rsp+38h] to mov the value of b into the rax register / / mov dword ptr [rax], and 0Ah sets the memory content of the address rax to 0AH (10) b = 10 00007FF7AAD01947 mov rax,qword ptr [rsp+38h] 00007FF7AAD0194C mov dword ptr [rax], 0Ah} 00007FF7AAD01952 mov rcx,rsp 00007FF7AAD01955 lea rdx, [00007FF7AAD09E30h] 00007FF7AAD0195C call 00007FF7AAD01221 00007FF7AAD01961 add rsp,40h 00007FF7AAD01965 pop rdi 00007FF7AAD01966 ret2, reference sample code # includevoid fun (int & a) {a = 10;} int main () {int a = 1; fun (a) Std::cout