A pointer contains the memory address of another variable. It points to the memory address, which is why it's called a pointer.
포인터는 메모리 주소를 저장한다. 메모리 주소를 가리킨다(points to)고 생각하면 된다.
#include <stdio.h>
int main()
{
int a=5;
int *pointer;
pointer =&a;
printf("%p\n", &a);
printf("%p\n", pointer);
return 0;
}
OUTPUT
0x16af43168
0x16af43168
Use '*' to declare an integer pointer variable.
*를 이용해 int 유형의 포인터 변수를 선언했다.
Assign the memory address of a variable to a pointer.
The ampersand '&' operator is used to get the memory address of a variable.
메모리 주소를 포인터에 할당했다.
&가 붙으면 그 변수의 메모리 주소를 말한다.
#include <stdio.h>
int main()
{
int a= 100;
int *ptr1;
int *ptr2;
ptr1=&a;
ptr2=&a;
*ptr1= 10;
printf("address : %p\n", ptr1);
printf("value :%d\n", *ptr1);
printf("address : %p\n", ptr2);
printf("value :%d\n", *ptr2);
return 0;
}
OUTPUT
address : 0x16bb77158
value :10
address : 0x16bb77158
value :10
Change the value of the pointer variable.
포인터 변수의 값을 바꿨다.
If we change the value stored at the memory address pointed to by ptr1, the value stored at the memory address pointed to by ptr2 also changes.
우리가 ptr1의 값을 바꾸면, ptr2도 같은 곳을 가리키고 있었기 때문에 ptr2의 값도 바뀐다.
"The concepts covered in Professor Son's 'Basic Algorithms' course"
손정우 교수님의 '기초 알고리즘' 강의에서 배운 내용이다.