-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab2-2.c
More file actions
55 lines (49 loc) ยท 3.04 KB
/
lab2-2.c
File metadata and controls
55 lines (49 loc) ยท 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
int main()
{
int i; //intํ ๋ณ์ i ์ ์ธ
int *ptr; //intํ ํฌ์ธํฐ ๋ณ์ ptr ์ ์ธ
int **dptr; //intํ ์ด์ค ํฌ์ธํฐ ๋ณ์ dptr ์ ์ธ
i = 1234; //i์ ์ ์ 1234 ์ ์ฅ
printf("[----- [Your Name] [Student ID] -----]\n"); //""์์ ๋ด์ฉ ์ถ๋ ฅ
printf("\t์ต๋์ง\t 2019038016\t\n\n"); //""์ ๋ด์ฉ์ธ ์ด๋ฆ, ํ๋ฒ ์ถ๋ ฅ
//ptr = &i์ด์
printf("[checking values before ptr = &i] \n"); //""์์ ๋ด์ฉ ์ถ๋ ฅ
printf("value of i == %d\n", i); //i์ ๊ฐ 10์ง์๋ก ์ถ๋ ฅ
printf("address of i == %p\n", &i); //i์ ์ฃผ์๊ฐ 16์ง์๋ก ์ถ๋ ฅ
printf("value of ptr == %p\n", ptr); //prt์ ๊ฐ 16์ง์๋ก ์ถ๋ ฅ
printf("address of ptr == %p\n", &ptr); //ptr์ ์ฃผ์๋ฅผ 16์ง์๋ก ์ถ๋ ฅ
ptr = &i; /* ptr is now holding the address of i */
//ptr = &i ์ดํ
printf("\n[checking values after ptr = &i] \n"); //""์์ ๋ด์ฉ ์ถ๋ ฅ
printf("value of i == %d\n", i); //i์ ๊ฐ 10์ง์๋ก ์ถ๋ ฅ
printf("address of i == %p\n", &i); //i์ ์ฃผ์๊ฐ 16์ง์๋ก ์ถ๋ ฅ
printf("value of ptr == %p\n", ptr); //prt์ ๊ฐ 16์ง์๋ก ์ถ๋ ฅ (=i์ ์ฃผ์๊ฐ)
printf("address of ptr == %p\n", &ptr); //ptr์ ์ฃผ์๊ฐ 16์ง์๋ก ์ถ๋ ฅ
printf("value of *ptr == %d\n", *ptr); //ptr์ ์ฃผ์๊ฐ ๊ฐ๋ฆฌํค๋ ๊ฐ 10์ง์๋ก ์ถ๋ ฅ(=i์ ๊ฐ)
dptr = &ptr; /* dptr is now holding the address of ptr */
//dptr = %ptr ์ดํ
printf("\n[checking values after dptr = &ptr] \n"); //""์์ ๋ด์ฉ ์ถ๋ ฅ
printf("value of i == %d\n", i); //i์ ๊ฐ 10์ง์๋ก ์ถ๋ ฅ
printf("address of i == %p\n", &i); //i์ ์ฃผ์๊ฐ 16์ง์๋ก ์ถ๋ ฅ
printf("value of ptr == %p\n", ptr); //prt์ ๊ฐ 16์ง์๋ก ์ถ๋ ฅ (=i์ ์ฃผ์๊ฐ)
printf("address of ptr == %p\n", &ptr); //ptr์ ์ฃผ์๊ฐ 16์ง์๋ก ์ถ๋ ฅ
printf("value of *ptr == %d\n", *ptr); //ptr์ ์ฃผ์๊ฐ ๊ฐ๋ฆฌํค๋ ๊ฐ 10์ง์๋ก ์ถ๋ ฅ (=i์ ๊ฐ)
printf("value of dptr == %p\n", dptr); //dptr์ ๊ฐ 16์ง์๋ก ์ถ๋ ฅ (=ptr์ ์ฃผ์๊ฐ)
printf("address of dptr == %p\n", &dptr); //dptr์ ์ฃผ์๊ฐ 16์ง์๋ก ์ถ๋ ฅ
printf("value of *dptr == %p\n", *dptr); //dptr์ด ๊ฐ๋ฆฌํค๋ ๊ฐ 16์ง์๋ก ์ถ๋ ฅ (=ptr์ ๊ฐ)
printf("value of **dptr == %d\n", **dptr); //dptr์ด ๊ฐ๋ฆฌํค๋๊ฐ(ptr์๊ฐ)์ ๊ฐ๋ฆฌํค๋๊ฐ ์ถ๋ ฅ (=i์ ๊ฐ)
*ptr = 7777; /* changing the value of *ptr */
//*ptr = 7777 ์ดํ
printf("\n[after *ptr = 7777] \n"); //""์์ ๋ด์ฉ ์ถ๋ ฅ
printf("value of i == %d\n", i); //i์ ๊ฐ 10์ง์๋ก ์ถ๋ ฅ
printf("value of *ptr == %d\n", *ptr); //ptr์ ์ฃผ์๊ฐ ๊ฐ๋ฆฌํค๋ ๊ฐ 10์ง์๋ก ์ถ๋ ฅ (=i์ ๊ฐ)
printf("value of **dptr == %d\n", **dptr); //dptr์ด ๊ฐ๋ฆฌํค๋๊ฐ(ptr์๊ฐ)์ ๊ฐ๋ฆฌํค๋๊ฐ ์ถ๋ ฅ (=i์ ๊ฐ)
**dptr = 8888; /* changing the value of **dptr */
//*ptr = 8888 ์ดํ
printf("\n[after **dptr = 8888] \n"); //""์์ ๋ด์ฉ ์ถ๋ ฅ
printf("value of i == %d\n", i); //i์ ๊ฐ 10์ง์๋ก ์ถ๋ ฅ
printf("value of *ptr == %d\n", *ptr); //ptr์ ์ฃผ์๊ฐ ๊ฐ๋ฆฌํค๋ ๊ฐ 10์ง์๋ก ์ถ๋ ฅ (=i์ ๊ฐ)
printf("value of **dptr == %d\n", **dptr); //dptr์ด ๊ฐ๋ฆฌํค๋๊ฐ(ptr์๊ฐ)์ ๊ฐ๋ฆฌํค๋๊ฐ ์ถ๋ ฅ (=i์ ๊ฐ)
return 0;
}