#include <stdio.h>
int main()
{
int a = 10;
int *pa = &a;
*pa = 20;
printf("%d", a);
return 0;
}
In this code, the 10 assigned to the memory digit of a is changed to 20 Is it right to change it to 20 when printing it with printf?
I'm sorry to ask you such a basic question.
pointer
Yes, that's right.
I tested it with a c++ interpreter called cling.
Look carefully at the memory address.
Also, the part that can be confused when expressing the pointer is the int *pa=&a
mark, which is better to read by attaching * to the data type in the form of int *pa=&a
. In other words, it reads naturally, "The variable pa is the int pointer type."
[cling]$ int a = 10
(int) 10
[cling]$ &a
(int *) 0x7fa318174010
[cling]$ int *pa = &a
(int *) 0x7fa318174010
[cling]$ *pa = 20
(int) 20
[cling]$ pa
(int *) 0x7fa318174010
[cling]$ a
(int) 20
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
620 Uncaught (inpromise) Error on Electron: An object could not be cloned
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.