C++/헷갈리는것들 정리
주소 관련
김띠띵
2021. 7. 15. 16:18
- 더블포인터에 이차원 배열의 이름이 대입되지 않는다
더보기


+1을 하면 더해지는 주소의 양이 다르다


배열의 이름은 첫번째 원소의 주소이다
a의 첫번째 원소는 int형의 주소, 그러므로 포인터에 대입이 가능하다
aa의 첫번째 원소는 &(aa[0][0])이 아니라 &(aa[0]) 이다
예로
첫번째 원소는 int형을 5개 가진 aa[0]이고
두번째 원소는 int형을 5개가진 aa[1]이다.
고로 aa는 int[5]의 배열이다
그럼 &(aa[0]) 의 자료형은 int (*) [5](int형 5개를 가진 포인터)
int형의 더블포인터 와 int[5]를 가진 포인터는 다르다
paa는 int*의 주소이다(int**)
그러므로 int(*)[5]와 int** 는 다른 자료형이기에 대입이 되지않는다

이게 헷갈리는 이유중 하나는 둘다 참조를 두번하면 int형이 나오는게 동일해서일듯싶다

밑에서 aa[0][0]과 paa[0][0]의 자료형은 같다
aa[0]과 paa[0]의 자료형은 위에서처럼 다르다
배열자료형을 잊지말장
- 포인터는 1차원배열과도 같다고 생각한다