보다 확한 인터 설명을 위한 제와 자료들
1ass='dot'>. 단 문제 ass='perma' href='#s-1'>B6;h2>d="sc-1">
답은 이지 단에 있습니다. class='line-anchor' id='line-6'>pan>
>
1.lass='line-anchor' id='line-7'>n>
~cpp
int a = 1;
int b = 2;
int* c;
int* d;
c = &a;
d = &a;
b = 4;
a = 3;
*c + a + *d = ?
ass='line-anchor' id='line-21'>n>
답은 이지 단에 있습니다. class='line-anchor' id='line-6'>pan>
> 1.lass='line-anchor' id='line-7'>n>
> 1.lass='line-anchor' id='line-7'>n>
~cpp int a = 1; int b = 2; int* c; int* d; c = &a; d = &a; b = 4; a = 3; *c + a + *d = ?ass='line-anchor' id='line-21'>n>
2.1class='dot'>.n> span>Swap ='perma' href='#s-2.1'>6;3>="sc-3">
두 수 값을 변경한다. class='line-anchor' id='line-24'>span>
/>
포인터를 쓰 않을 경우와 비교면 이가 쉽다. class='line-anchor' id='line-25'>span>
/>
~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;
}
두 수 값을 변경한다. class='line-anchor' id='line-24'>span>
/> 포인터를 쓰 않을 경우와 비교면 이가 쉽다. class='line-anchor' id='line-25'>span>
/>
/> 포인터를 쓰 않을 경우와 비교면 이가 쉽다. class='line-anchor' id='line-25'>span>
/>
~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.2class='dot'>.n> span>배의 출력 ass='perma' href='#s-2.2'>¶
배열이름은 열 맨(array<a href='/wiki.php/0' >0)을 나낸다.
int array5an> = {1,2,3,4,5}서 array<a class='nonexistent' rel='nofollow' href='/wiki.php/i'>ispan>가 뜻하는 것은 *(array+i)이다.pan class='line-anchor' id='line-82'><br />
int array5an> = {1,2,3,4,5}서 array<a class='nonexistent' rel='nofollow' href='/wiki.php/i'>ispan>가 뜻하는 것은 *(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.3class='dot'>.n> span>n>s='nonexistent' rel='nofollow' href='/wiki.php/%EC%9D%B4%EC%98%81%ED%98%B8'>이a>영호</span> 성 lass='perma' href='#s-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)