#include <stdio.h>

int main() {
     // 포인터 * : 주소를 저장하는 변수 
     // 포인터 변수 선언
     int *p;

     // 주소 연산자 & : 변수의 주소
     int a = 10;
     printf("a의 값 = %d\n", a);
     printf("a의 주소 = %p\n", &a);

     int * b = &a;
     printf("a의 주소 = %p\n", b);

     // 간접 참조 연산자 * : 포인터 변수가 가리키는 주소의 값
     printf("a의 값 = %d\n", *b);

     int x = 3, y = 7;
     int *ptr = &x;
     
     *ptr = y;   //x = 7
     ptr = &y;    
     *ptr = 10;  //y = 10

     // x, y, ptr에 저장된 값?
     printf("x의 값 : %d, 주소 : %p\n", x, &x);
     printf("y의 값 : %d, 주소 : %p\n", y, &y);
     printf("ptr에 저장된 주소 : %p\n", ptr);
     // printf("ptr이 가리키는 값 : %d\n", *ptr);


     int num1 = 8, num2 = 15;
     int *ptr1 = &num1;
     int *ptr2 = &num2;

     *ptr1 = *ptr2; //num1 = 15
     ptr2 = ptr1;   //ptr2 = &num1
     *ptr2 = 50;    //num1 = 50
     //num1, num2, ptr1, ptr2의 값?
     printf("num1의 값 : %d, 주소 : %p\n", num1, &num1);
     printf("num2의 값 : %d, 주소 : %p\n", num2, &num2);
     printf("ptr1이 가리키는 값 : %d, 저장된 주소 : %p\n", *ptr1, ptr1);
     printf("ptr2이 가리키는 값 : %d, 저장된 주소 : %p\n", *ptr2, ptr2);

    
     int i = 1;
     int j = 2;
     int k = 3;
     int *p1 = &i;
     *p1 = *p1 * 3; // i = i * 3 = 3
     int *p2 = p1;  // p2 = &i
     *p2 = *p2 - 1; // i = i - 1 = 2
     
     return 0;

}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: