보다 명확한 í�¬ì�¸í„° 설명ì�„ 위한 ì˜ˆì œì™€ ìž�료들
1. 간단 ë¬¸ì œ ¶
답� 페�지 하단� 있습니다.
1.
1.
~cpp int a = 1; int b = 2; int* c; int* d; c = &a; d = &a; b = 4; a = 3; *c + a + *d = ?
2.1. Swap ¶
� 수� 값� 변경한다.
��터를 쓰지 않� 경우와 비�하면 �해가 쉽다.
��터를 쓰지 않� 경우와 비�하면 �해가 쉽다.
~cpp
#include <stdio.h>
void Swap(int* aX, int* aY);
int main()
{
int x = 1;
int y = 2;
printf("x = %d\ny = %d\n� 변수� 값� �환합니다.\n", x, y);
Swap(&x, &y);
printf("x = %d\ny = %d\n", x, y);
system("PAUSE");
return 0;
}
void Swap(int* aX, int* aY){
int temp;
temp = *aX;
*aX = *aY;
*aY = temp;
}
~cpp
#include <stdio.h>
void Swap(int aX, int aY);
int main()
{
int x = 1;
int y = 2;
printf("x = %d\ny = %d\n� 변수� 값� �환합니다.\n", x, y);
Swap(x, y);
printf("x = %d\ny = %d\n", x, y);
system("PAUSE");
return 0;
}
void Swap(int aX, int aY){
int temp;
temp = aX;
aX = aY;
aY = temp;
}
2.2. ë°°ì—´ì�˜ ì¶œë ¥ ¶
배열�름� 배열 맨앞(array0)� 나타낸다.
int array5 = {1,2,3,4,5}�서 arrayi가 뜻하는 것� *(array+i)�다.
int array5 = {1,2,3,4,5}�서 arrayi가 뜻하는 것� *(array+i)�다.
~cpp
#include <stdio.h>
void ArrayOutput(int* aArray, int aSize);
int main()
{
int array[] = {1, 2, 3, 4, 5};
printf("ë°°ì—´ì�„ ì¶œë ¥í•©ë‹ˆë‹¤.\n");
ArrayOutput(array, sizeof(array)/sizeof(int));
int array2 = *(array+2);
printf("\narray[2]� 값� %d입니다\n", array2);
system("pause");
return 0;
}
void ArrayOutput(int* aArray, int aSize){
int i;
for (i=0; i<aSize; i++){
printf("array[%d] = %d\n", i, aArray[i]);
}
}
2.3. ì�´ì˜�호 작성 ¶
~cpp
main(){
int a;
int *pb, **pc;
a=10;
pb=&a;
pc=&pb;
printf("\n\n\n\tint a=10, *pb=&a, **pc=&pb\n\n");
printf("\t\t&pc=%d\tpc=%d\t*pc=%d\t**pc=%d\n", &pc, pc, *pc, **pc);
printf("\t\t&pb=%d\tpb=%d\t*pb=%d\n", &pb, pb, *pb);
printf("\t\t&a=%d\ta=%d\n\n\n\n", &a, a);
printf("\t\ta=%d\t\t*pb=%d\t\t**pc=%d\n", a, *pb, **pc);
printf("\t\t&a=%d\tpb=%d\t*pc=%d\n", &a, pb, *pc);
printf("\t\t&pb=%d\tpc=%d\n\n\n\n", &pb, pc);
}
~cpp int a=10, *pb=&a, **pc=&pb &a=2293620 a=10 &pb=2293616 pb=2293620 *pb=10 // pbì�˜ ê°’ì�€ aì�˜ 주소ì�´ë‹¤. &pc=2293612 pc=2293616 *pc=2293620 **pc=10 // pcì�˜ ê°’ì�€ *pb변수ì�˜ 주소ì�´ë‹¤. ê·¸ë¦¬ê³ *pc는 pbì�˜ ê°’ì�„ 나타낸다. **pc는 *pb(==a)ì�˜ ê°’ì�„ 나타낸다. a=10 *pb=10 **pc=10 &a=2293620 pb=2293620 *pc=2293620 &pb=2293616 pc=2293616 위ì—�서 pc를 (변수)ë�¼ê³ ê°€ì •í•˜ìž�. &(변수) -> í•ìƒ� 변수1ì�˜ 주소를 뜻한다. (변수) -> í•ìƒ� 변수ì�˜ ê°’ì�„ 뜻한다. 별표가 ë¶™ì�€ 것ì�€ (변수)ì�˜ ê°’ì�´ 아니다. ê°’ì�€ í•ìƒ� (변수)ì—�ë§Œ 들어간다. (pc = &pb) 별표가 나타내는 ê°’ì�€ í�¬ì�¸í„°ê°€ 가리키는 ê°’(주소)ì�˜ ê°’ì�´ë‹¤. **pcì—�서 중요한 것ì�€ **pcìž�ì²´ì�˜ 주소ì�¸ &pc와 **pcì�˜ ê°’ì�¸ pc ë¿�ì�´ë‹¤. 별표는 ê·¸ 변수가 í‘œì‹œí•˜ê³ ìžˆëŠ” 메모리 주소(여기ì—�ì„ ê°’)로 ì�´ë�™í•´ì„œ ê·¸ ê°’ì�„ ì¶œë ¥í•˜ëŠ” 것ì�´ë�¼ê³ ìƒ�ê°�하면 편하다. pc == *(&pc) *pc == **(&pc)










