Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pcc022
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
이소현
pcc022
Commits
4f92638d
Commit
4f92638d
authored
3 years ago
by
이소현
Browse files
Options
Downloads
Patches
Plain Diff
Update README.md
parent
7da74673
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+86
-0
86 additions, 0 deletions
README.md
with
86 additions
and
0 deletions
README.md
+
86
−
0
View file @
4f92638d
...
...
@@ -370,7 +370,93 @@ int count_one(unsigned int a)
}
```
## lesson06
*
bash에 있는 빌트인 명령어들은
>* $man ~ or $which ~ 를 해도 뜨지 않는다.
*
$alias cc='cc -Wall' : alias 명령어를 이용하여 cc명령어만 입력하면 자동으로 cc -Wall을 실행하게 만들 수 있다.
*
$alias -p : alias 된 것을 모두 보여준다
*
$
\#
: # 사용을 alias 를 해놓은 것을 사용하지 않고 오리지널을 사용하고 싶을때
\를
붙여 명령한다.
*
일반적으로 alias는 로그아웃을 하면 명령한 것들이 사라진다. 이때 로그아웃 후에도 계속 유지시키고 싶다면
>* vi ~/.bashrc 로 가서 alias 설정을 해야한다.
>* source !$ : 방금 수행한 것을 컴파일
>* unalias # : 는 alias로 설정한 #를 없앤다.
1.
pointer
>* usr/include 에 가서 limits.h에 가면 int, long long, 등의 bit수를 확인 가능하다.
>1. "&" 기호
>>* &a : address operator
>>* a & b : bit wise and operator
>2. void *c : 함수의 포인터 void는 char 포인터와 비슷하지만 다른 용도로 사용된다.
>* 주소값은 음수가 없으므로 unsigned 값이다.
*
pointer 성질을 보기 위한 실습코드
```
C
#include<stdio.h>
int add(int *a, int *b, int *c)
{
*c = *a + *b;
}
int main()
{
const int a = 100;
int b = 200;
long long c = 999;
// int * == long long
fprintf(stdout, "%d : %lld %llx\n", a, &a, &a);
fprintf(stdout, "%d : %lld %llx\n", b, &b, &b);
add(&a, &b ,&c);
//c = a+b
fprintf(stdout, "%d : %lld %llx\n", c, &c, &c);
fprintf(stdout, "%d : %lld %llx\n", c, &c+1, &c+1);
fprintf(stdout, "%d : %lld %llx\n", c, &c+2, &c+2);
}
```
## lesson07
```
C
int main()
{
const int a = 100;
int b = 200;
int c = 9999;
int *p = &a;
fprintf(stdout, "a b c: %d %d %d\n", a,b,c);
*p = 200;
fprintf(stdout, "a b c: %d %d %d\n", a,b,c);
}
```
*
위의 코드를 살펴보면 a는 const로 설정되어 있는 것을 볼 수 있는데 아래에서
*p = &a로 정의하고 *
p에 200을 넣어줌으로써 a의 값을 변환하고 있다.
*
위와 같은 행동을 하면 const는 수정이 불가능함에도 수정이 되는 것을 볼 수 있다.
*
즉, a 자체에 할당하는 것은 수정이 불가능하지만 포인트를 통해서는 수정이 가능해진다는 것이다.
*
그렇다면 굳이 왜 const를 사용하는 것일까?
>* 왜냐하면 값이 변경될 때 프로그래머에게 경고를 줌으로써 일종의 안전장치를 만들 수 있기 때문이다.
*
위의 코드에 아래의 코드를 각각 넣어 실행하게 된다면
```
C
int const *p = &a;
int * const q = &a;
```
*
p의 경우 int const 타입을 가르키는 포인터 이므로 p =
&b;
를 하여도 에러가 나지 않고 수행이 가능하다.
*
하지만 q 의 경우 const 타입의 포인터가 int를 가르키는 형태로 q 자체가 const이므로 q = &b 를 하게 되면 에러를 뱉어낸다.
*
따라서 int const
*
p 형태로 정의해야만 pointer 를 통해서 값을 바꿀 수 있게된다.
*
함수의 포인터
>* 실습에서 작성한 fnpointer.c 파일을 살펴보면
```
C
void (*fp[4])(int *, int *, int *) = {add, sub, mul, div};
```
>* 형태로 함수의 포인터를 정의 한 것을 볼 수 있다. 이때 함수를 배열로 받았는데 (*fp[4])를 받는 위치를 void 바로 뒤에 써야한다.
* $od : 8진수로 보여줌
* $od -x : 16진수로 보여줌
* (ex $od a.out )
## lesson08
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment