#include <stdio.h>
int main() {
// 포인터 * : 주소를 저장하는 변수
// 포인터 변수 선언
int *p;
// 주소 연산자 & : 변수의 주소를 나타낸다
int a = 10;
printf("a의 값 = %d\n", a);
printf("a의 주소 = %p\n", &a); //주소는 %p
int *b = &a;
printf("a의 주소 = %p\n", b);
// 간접 참조 연산자 * : 포인터 변수가 가리키는 주소의 값
printf("a의 값 = %d\n", *b);
int x = 3;
int y = 7;
int *ptr = &x;
*ptr = y; // x = 7
ptr = &y; // ptr = &y
*ptr = 10; // y = 10
printf("x = %d\n", x);
printf("y = %d\n", y);
printf("ptr = %p\n", ptr);
printf("----문제----\n");
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\n", num1);
printf("num2 = %d\n", num2);
printf("num1의 주소 = %p\n", &num1);
printf("num2의 주소 = %p\n", &num2);
printf("ptr1 = %p\n", ptr1);
printf("ptr2 = %p\n", ptr2);
printf("----숙제----\n");
int c1 = 13;
int c2 = 26;
int *k = &c1;
int *t = &c2;
*k = *t; // c1 = 26
t = k; // t = &c1
*t = 50; // c1 = 50
k = &c2;
*k = 7; // c2 = 7
// c1, c2, k, t의 값을 예측해서 아래 답을 채워보세요.
// c1 = 50
// c2 = 7
// k = &c2 (c2의 주소)
// t = &c1 (c1의 주소)
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: