배열과 포인터
큰꽃늘
2023.04.01
질문 내용 :
#include stdio.h
int main(void)
{
int a[5] = {1,2,3,4,5};
int* p;
p=a;
printf(%d\t, *(p+1));
printf(%d\t, *(p+2));
printf(%d\t, a[0]);
printf(%d\t, a[3]);
printf(%d\t, p[1]);
printf(%d\t, p[2]);
printf(%d\t, *(a+1));
printf(%d\t, *(a+2));
printf(%d\t, *(++p));
printf(%d\t, *(++p));
printf(%d\t, a[0]);
printf(%d\t, a[1]);
printf(%d\t, p[0]);
printf(%d\t, p[1]);
}
밑에서 빨간색 6개의 값이 왜 2 3 1 2 3 4 가 나오는지 모르겠습니다.
제 생각에는 2 2 1 2 1 2 가 나와야 할 것 같은데 말이죠......
포인터에 *(p+1), *(p+2) ... 해주는것과 p++, ++p 해주는게 다르다고도 하던데
그것 때문인가요...? 어떻게 다른지 알고싶습니다...