SlideShare a Scribd company logo
1 of 26
Download to read offline
int a = 10, b = 20;
int *p; // p
p = &a; // p a
p
!
a
!
(4byte) (4byte)
int a = 10, b = 20;
int *p; // p
p = &a; // p a
6000 …
6004 …
6008 …
p " 6012 6020
b " 6016 20
a " 6020 10
6024 …
6028 …
6032 …
6036 …
printf("%d", p);
6020
6000 …
6004 …
6008 …
p " 6012 6020
b " 6016 20
a " 6020 10
6024 …
6028 …
6032 …
6036 …
int a = 10, b = 20;
int *p; // p
p = &a; // p a
printf("%d", *p);
10
int a = 10, b = 20;
int *p;
p = &a;
*p += 5;
printf("%dn", a);
15
int *p;
p (int *)
*p int
int *p;
int* p;
p int
int *a, b;
a (int *)
*a int
b int
*b
int *a, *b;
a (int *)
*a int
b (int *)
*b int
void swap(int *v1, int *v2) {
int temp = *v1;
*v1 = *v2;
*v2 = temp;
}
int main() {
int a = 10, b = 20; int *p = &a;
swap(_____, _____);
printf("%d %dn", a, b);
return 0;
} 20 10
void swap(int *v1, int *v2) {
int temp = *v1;
*v1 = *v2;
*v2 = temp;
}
int main() {
int a = 10, b = 20; int *p = &a;
swap(&a, &b); // swap(p, &b);
printf("%d %dn", a, b);
return 0;
} 20 10
void swap(int *v1, int *v2) {
int temp = *v1;
*v1 = *v2;
*v2 = temp;
}
int main() {
int a = 10, b = 20;
int *p = &a;
swap(&a, &b);
printf("%d %dn", a, b);
return 0;
}
3538
3542
3546
temp " 3550
v2 " 3554
v1 " 3558
p " 7580
b " 7584
a " 7588
3132 …
3136 …
p " 3140
i " 3144
3148 …
arr[0]" 3152
arr[1]" 3156
arr[2]" 3160
arr[3]" 3164
arr[4]" 3168
int arr[5] = {0,};
int i, *p = arr;
printf("arr: %dn", arr);
for (i = 0; i < 5; i++)
printf("arr[%d]: %dn", i, &arr[i]);
3132 …
3136 …
p " 3140
i " 3144
3148 …
arr[0]" 3152
arr[1]" 3156
arr[2]" 3160
arr[3]" 3164
arr[4]" 3168
← p + 1
← p
← p + 3
← p + 2
← p + 4
int arr[5] = {2, 3, 5, 7, 9};
int i;
for (i = 0; i < 5; i++)
printf("%d %dn", arr[i], *(arr + i));
*(arr + i) arr[i]
int strlen(char *s) {
int n;
for (n = 0; *s != '0'; s++)
n++;
return n;
}
int main() {
char str[128]; int res;
scanf("%s", str);
res = strlen(str);
printf("length: %dn", res);
return 0;
}
int arr[5][5];
int i, j;
for (i = 0; i < 5; i++)
for (j = 0; j < 5; j++)
arr[i][j] = i * 5 + j;
arr[0] 0 1 2 3 4
arr[1] 5 6 7 8 9
arr[2] 10 11 12 13 14
arr[3] 15 16 17 18 19
arr[4] 20 21 22 23 24
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++)
printf("%2d ", *(*(arr + i) + j));
printf("n");
}
(int *)
int *pi
+1 sizeof(int)
arr[0] 0 1 2 3 4
arr[1] 5 6 7 8 9
arr[2] 10 11 12 13 14
arr[3] 15 16 17 18 19
arr[4] 20 21 22 23 24
for (i = 0; i < 5; i++) {
int *pb = arr[i];
for (j = 0; j < 5; j++) {
printf("%2d ", *pb);
pb++;
}
printf("n");
}
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++)
printf("%2d ", *(*(arr + i) + j));
printf("n");
}
__________
+1 sizeof(int)*5
arr[0] 0 1 2 3 4
arr[1] 5 6 7 8 9
arr[2] 10 11 12 13 14
arr[3] 15 16 17 18 19
arr[4] 20 21 22 23 24
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++)
printf("%2d ", *(*(arr + i) + j));
printf("n");
}
int (*)[5]
int (*p)[5]
+1 sizeof(int)*5
arr[0] 0 1 2 3 4
arr[1] 5 6 7 8 9
arr[2] 10 11 12 13 14
arr[3] 15 16 17 18 19
arr[4] 20 21 22 23 24
int (*pa)[5] = arr;
for (i = 0; i < 5; i++) {
int *pb = *pa;
for (j = 0; j < 5; j++) {
printf("%2d ", *pb);
pb++;
}
printf("n");
pa++;
}
int a = 20, b = 10, c = 30, i;
int *pArr[3] = {&a, &b, &c};
for (i = 0; i < 3; i++)
printf("%d ", *pArr[i]);
C언어 스터디 강의자료 - 4차시

More Related Content

What's hot

listing output program C
listing output program Clisting output program C
listing output program CAdjievanGestu
 
Bcsl 033 data and file structures lab s4-3
Bcsl 033 data and file structures lab s4-3Bcsl 033 data and file structures lab s4-3
Bcsl 033 data and file structures lab s4-3Dr. Loganathan R
 
C Program : Sorting : Bubble,
C Program : Sorting : Bubble, C Program : Sorting : Bubble,
C Program : Sorting : Bubble, Meita Jayani
 
Structure of c program | CS8251 | Programming in c | Learn Hub
Structure of c program | CS8251 | Programming in c | Learn HubStructure of c program | CS8251 | Programming in c | Learn Hub
Structure of c program | CS8251 | Programming in c | Learn HubLearn Hub
 
Bcsl 033 data and file structures lab s1-2
Bcsl 033 data and file structures lab s1-2Bcsl 033 data and file structures lab s1-2
Bcsl 033 data and file structures lab s1-2Dr. Loganathan R
 
PROBLEMAS DE PROGRAMACION 2 por jordan puente quinto
PROBLEMAS DE PROGRAMACION 2 por jordan puente quintoPROBLEMAS DE PROGRAMACION 2 por jordan puente quinto
PROBLEMAS DE PROGRAMACION 2 por jordan puente quintoJordan Puente
 
[程式設計]標準差
[程式設計]標準差[程式設計]標準差
[程式設計]標準差Hui-Shih Leng
 
(Meta 4) ejemplo calcular la mitad de un numero dev c++
(Meta 4) ejemplo calcular la mitad de un numero dev c++ (Meta 4) ejemplo calcular la mitad de un numero dev c++
(Meta 4) ejemplo calcular la mitad de un numero dev c++ Eli Diaz
 
Func menu mostrar.c
Func menu mostrar.cFunc menu mostrar.c
Func menu mostrar.calbertinous
 

What's hot (20)

listing output program C
listing output program Clisting output program C
listing output program C
 
Bcsl 033 data and file structures lab s4-3
Bcsl 033 data and file structures lab s4-3Bcsl 033 data and file structures lab s4-3
Bcsl 033 data and file structures lab s4-3
 
Include
IncludeInclude
Include
 
07 3 do-while반복문
07 3 do-while반복문07 3 do-while반복문
07 3 do-while반복문
 
C Program : Sorting : Bubble,
C Program : Sorting : Bubble, C Program : Sorting : Bubble,
C Program : Sorting : Bubble,
 
質數的判斷
質數的判斷質數的判斷
質數的判斷
 
Doi xung mang mot chieu
Doi xung mang mot chieuDoi xung mang mot chieu
Doi xung mang mot chieu
 
Structure of c program | CS8251 | Programming in c | Learn Hub
Structure of c program | CS8251 | Programming in c | Learn HubStructure of c program | CS8251 | Programming in c | Learn Hub
Structure of c program | CS8251 | Programming in c | Learn Hub
 
Bcsl 033 data and file structures lab s1-2
Bcsl 033 data and file structures lab s1-2Bcsl 033 data and file structures lab s1-2
Bcsl 033 data and file structures lab s1-2
 
PROBLEMAS DE PROGRAMACION 2 por jordan puente quinto
PROBLEMAS DE PROGRAMACION 2 por jordan puente quintoPROBLEMAS DE PROGRAMACION 2 por jordan puente quinto
PROBLEMAS DE PROGRAMACION 2 por jordan puente quinto
 
[程式設計]標準差
[程式設計]標準差[程式設計]標準差
[程式設計]標準差
 
(Meta 4) ejemplo calcular la mitad de un numero dev c++
(Meta 4) ejemplo calcular la mitad de un numero dev c++ (Meta 4) ejemplo calcular la mitad de un numero dev c++
(Meta 4) ejemplo calcular la mitad de un numero dev c++
 
B.f.s
B.f.sB.f.s
B.f.s
 
Fibonacci
FibonacciFibonacci
Fibonacci
 
Func menu mostrar.c
Func menu mostrar.cFunc menu mostrar.c
Func menu mostrar.c
 
Alocação Dinâmica em C
Alocação Dinâmica em CAlocação Dinâmica em C
Alocação Dinâmica em C
 
Introduction to TDD in C
Introduction to TDD in CIntroduction to TDD in C
Introduction to TDD in C
 
N primo clase programa
N primo clase programaN primo clase programa
N primo clase programa
 
Mcm
McmMcm
Mcm
 
Alprog
AlprogAlprog
Alprog
 

More from Junha Jang

Flask 소수전공 강의자료 - 4차시
Flask 소수전공 강의자료 - 4차시Flask 소수전공 강의자료 - 4차시
Flask 소수전공 강의자료 - 4차시Junha Jang
 
Flask 소수전공 강의자료 - 3차시
Flask 소수전공 강의자료 - 3차시Flask 소수전공 강의자료 - 3차시
Flask 소수전공 강의자료 - 3차시Junha Jang
 
Flask 소수전공 강의자료 - 1차시
Flask 소수전공 강의자료 - 1차시Flask 소수전공 강의자료 - 1차시
Flask 소수전공 강의자료 - 1차시Junha Jang
 
Flask 소수전공 강의자료 - 2차시
Flask 소수전공 강의자료 - 2차시Flask 소수전공 강의자료 - 2차시
Flask 소수전공 강의자료 - 2차시Junha Jang
 
Java 스터디 강의자료 - 1차시
Java 스터디 강의자료 - 1차시Java 스터디 강의자료 - 1차시
Java 스터디 강의자료 - 1차시Junha Jang
 
C언어 스터디 강의자료 - 5차시
C언어 스터디 강의자료 - 5차시C언어 스터디 강의자료 - 5차시
C언어 스터디 강의자료 - 5차시Junha Jang
 
C언어 스터디 강의자료 - 1차시
C언어 스터디 강의자료 - 1차시C언어 스터디 강의자료 - 1차시
C언어 스터디 강의자료 - 1차시Junha Jang
 

More from Junha Jang (7)

Flask 소수전공 강의자료 - 4차시
Flask 소수전공 강의자료 - 4차시Flask 소수전공 강의자료 - 4차시
Flask 소수전공 강의자료 - 4차시
 
Flask 소수전공 강의자료 - 3차시
Flask 소수전공 강의자료 - 3차시Flask 소수전공 강의자료 - 3차시
Flask 소수전공 강의자료 - 3차시
 
Flask 소수전공 강의자료 - 1차시
Flask 소수전공 강의자료 - 1차시Flask 소수전공 강의자료 - 1차시
Flask 소수전공 강의자료 - 1차시
 
Flask 소수전공 강의자료 - 2차시
Flask 소수전공 강의자료 - 2차시Flask 소수전공 강의자료 - 2차시
Flask 소수전공 강의자료 - 2차시
 
Java 스터디 강의자료 - 1차시
Java 스터디 강의자료 - 1차시Java 스터디 강의자료 - 1차시
Java 스터디 강의자료 - 1차시
 
C언어 스터디 강의자료 - 5차시
C언어 스터디 강의자료 - 5차시C언어 스터디 강의자료 - 5차시
C언어 스터디 강의자료 - 5차시
 
C언어 스터디 강의자료 - 1차시
C언어 스터디 강의자료 - 1차시C언어 스터디 강의자료 - 1차시
C언어 스터디 강의자료 - 1차시
 

C언어 스터디 강의자료 - 4차시

  • 1.
  • 2.
  • 3.
  • 4. int a = 10, b = 20; int *p; // p p = &a; // p a
  • 6. int a = 10, b = 20; int *p; // p p = &a; // p a 6000 … 6004 … 6008 … p " 6012 6020 b " 6016 20 a " 6020 10 6024 … 6028 … 6032 … 6036 … printf("%d", p); 6020
  • 7. 6000 … 6004 … 6008 … p " 6012 6020 b " 6016 20 a " 6020 10 6024 … 6028 … 6032 … 6036 … int a = 10, b = 20; int *p; // p p = &a; // p a printf("%d", *p); 10
  • 8. int a = 10, b = 20; int *p; p = &a; *p += 5; printf("%dn", a); 15
  • 9. int *p; p (int *) *p int int *p; int* p; p int
  • 10. int *a, b; a (int *) *a int b int *b int *a, *b; a (int *) *a int b (int *) *b int
  • 11. void swap(int *v1, int *v2) { int temp = *v1; *v1 = *v2; *v2 = temp; } int main() { int a = 10, b = 20; int *p = &a; swap(_____, _____); printf("%d %dn", a, b); return 0; } 20 10
  • 12. void swap(int *v1, int *v2) { int temp = *v1; *v1 = *v2; *v2 = temp; } int main() { int a = 10, b = 20; int *p = &a; swap(&a, &b); // swap(p, &b); printf("%d %dn", a, b); return 0; } 20 10
  • 13. void swap(int *v1, int *v2) { int temp = *v1; *v1 = *v2; *v2 = temp; } int main() { int a = 10, b = 20; int *p = &a; swap(&a, &b); printf("%d %dn", a, b); return 0; } 3538 3542 3546 temp " 3550 v2 " 3554 v1 " 3558 p " 7580 b " 7584 a " 7588
  • 14.
  • 15. 3132 … 3136 … p " 3140 i " 3144 3148 … arr[0]" 3152 arr[1]" 3156 arr[2]" 3160 arr[3]" 3164 arr[4]" 3168 int arr[5] = {0,}; int i, *p = arr; printf("arr: %dn", arr); for (i = 0; i < 5; i++) printf("arr[%d]: %dn", i, &arr[i]);
  • 16. 3132 … 3136 … p " 3140 i " 3144 3148 … arr[0]" 3152 arr[1]" 3156 arr[2]" 3160 arr[3]" 3164 arr[4]" 3168 ← p + 1 ← p ← p + 3 ← p + 2 ← p + 4
  • 17. int arr[5] = {2, 3, 5, 7, 9}; int i; for (i = 0; i < 5; i++) printf("%d %dn", arr[i], *(arr + i)); *(arr + i) arr[i]
  • 18. int strlen(char *s) { int n; for (n = 0; *s != '0'; s++) n++; return n; } int main() { char str[128]; int res; scanf("%s", str); res = strlen(str); printf("length: %dn", res); return 0; }
  • 19. int arr[5][5]; int i, j; for (i = 0; i < 5; i++) for (j = 0; j < 5; j++) arr[i][j] = i * 5 + j; arr[0] 0 1 2 3 4 arr[1] 5 6 7 8 9 arr[2] 10 11 12 13 14 arr[3] 15 16 17 18 19 arr[4] 20 21 22 23 24
  • 20. for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) printf("%2d ", *(*(arr + i) + j)); printf("n"); } (int *) int *pi +1 sizeof(int) arr[0] 0 1 2 3 4 arr[1] 5 6 7 8 9 arr[2] 10 11 12 13 14 arr[3] 15 16 17 18 19 arr[4] 20 21 22 23 24
  • 21. for (i = 0; i < 5; i++) { int *pb = arr[i]; for (j = 0; j < 5; j++) { printf("%2d ", *pb); pb++; } printf("n"); }
  • 22. for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) printf("%2d ", *(*(arr + i) + j)); printf("n"); } __________ +1 sizeof(int)*5 arr[0] 0 1 2 3 4 arr[1] 5 6 7 8 9 arr[2] 10 11 12 13 14 arr[3] 15 16 17 18 19 arr[4] 20 21 22 23 24
  • 23. for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) printf("%2d ", *(*(arr + i) + j)); printf("n"); } int (*)[5] int (*p)[5] +1 sizeof(int)*5 arr[0] 0 1 2 3 4 arr[1] 5 6 7 8 9 arr[2] 10 11 12 13 14 arr[3] 15 16 17 18 19 arr[4] 20 21 22 23 24
  • 24. int (*pa)[5] = arr; for (i = 0; i < 5; i++) { int *pb = *pa; for (j = 0; j < 5; j++) { printf("%2d ", *pb); pb++; } printf("n"); pa++; }
  • 25. int a = 20, b = 10, c = 30, i; int *pArr[3] = {&a, &b, &c}; for (i = 0; i < 3; i++) printf("%d ", *pArr[i]);