Constant in C (part.2)

Han sang yeob·2021년 2월 15일
0

Basic of C language

목록 보기
9/9

As a programmer, we need to understand 3 things about constant.

1. What is a constant?
2. Why do constants exist?
3. Where and how are constants stored?

In short, Answers are

1. A constant, unlike a variable, is a data that will not change.
2. Constant exist because there is data that you do not want to modify or change. 
3. Constant is stored in read only portion of memory.

Let's imagine that we have two types of memory.

```
1. Read only
2. Read & Write.
```

This is actually not true because memory is just memory. But this is getting too deep for us to know so I will just consume like that.

But what we need to know is that differnet range of memories can be used as a different purposes.
Variables are placed in read/write portion of memory. Constant, however, is placed in read only memory portion of memory. Now, we might be asking 'why do we need this range of read only memory?'.
The answer is certain types of data that we create should not change because it might break down our program.
For example, we created a function which is desinged to draw circle and created a value of pie(3.14). Do we ever need to change this value?? The answer is "NO". We do not want someone or my program to change this value accidently into something else. If so, we need to have constant value of pie so that No one or program can change what is stored in value of pie.

profile
Learning IT in Vietnam

0개의 댓글