-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6109af
commit 23d685b
Showing
2 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# 07-19 | ||
|
||
## 독서 | ||
|
||
함께자라기와 쏙쏙 들어오는 함수형 코딩 독서시작함 | ||
완독부터 해보고 정리하는게 좋을듯함 | ||
|
||
## cpp pointer | ||
|
||
\*(애스터리스크)를 통한 pointer 선언 | ||
포인터 타입을 선언할때는 변수의 주소 타입과 일치해야함 | ||
|
||
```cpp | ||
<type> * <name> = <변수의 주소> | ||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
int a = 1; | ||
int main(){ | ||
// a의 타입과 일치해야함 | ||
int *b = &a; | ||
|
||
// 0x16b84b2f0 | ||
count << b << '\n'; | ||
return 0; | ||
} | ||
``` | ||
|
||
또한 a의 주소값이 아닌 원래의 변수값을 활용하려면 역참조연산을 통해 원래의 변수값 참조 가능 | ||
|
||
```cpp | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
int a = 1; | ||
int main(){ | ||
// a의 타입과 일치해야함 | ||
int *b = &a; | ||
|
||
// 1 | ||
count << *b << '\n'; | ||
return 0; | ||
} | ||
``` | ||
|
||
크기가 정해진 배열에서 레퍼런스 연산(&)을 사용하지 않아도 주소값 참조가능 | ||
|
||
```cpp | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
int a[3] = {1, 2, 3}; | ||
int main(){ | ||
// 배열의 첫번째 값 주소 | ||
int *c = a; | ||
|
||
// c == &a[0] | ||
cout << c << "\n"; | ||
cout << &a[0] << '\n'; | ||
|
||
// c + 1 == &a[1] | ||
cout << c + 1 << '\n'; | ||
cout << &a[1] << '\n'; | ||
|
||
return 0; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters