void swap(int *a, int *b){
int temp=*a;
*a=*b;
*b=temp;
}
As an example of call by reference in this way, we use pointers in frequently used functions.
While studying the memory area, I found out that the pointer was stored in the stack area If so, all variables will be erased after the method comes out, so how can the value change in the main be checked?
Maybe I don't understand it because I don't have enough understanding of the memory area TT...
Is the address value used in the pointer separate from the memory area?
c pointer
Pointers are not stored in the stack, but parameters or regional variables are stored in the stack.
Of course, in addition to the variables, the return address is also saved by the call opcode (this is independent of the above source).)
Variable cleared (stack cleared to be exact)...The reason why this function is valid is that the pointer variables a and b, which are parameters, are addressed to the regional variables created in the main.
This means that the address of the variable created in main will be entered as a parameter of the swap function, so it will not be removed from the swap function.
You need to be familiar with the system structure because the c language was originally designed as the system language.
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
582 PHP ssh2_scp_send fails to send files as intended
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.