C μΈμ΄μμ μμ(Constant)λ νλ‘κ·Έλ¨μμ λ³νμ§ μλ κ³ μ λ κ°μ λνλ λλ€. μμλ μ£Όλ‘ νλ‘κ·Έλ¨μμ μ¬μ©λλ κ° μ€μ λ³νμ§ μμμΌ νλ κ²½μ°μ μ¬μ©λ©λλ€. C μΈμ΄μμλ μμλ₯Ό λ€μ λ κ°μ§ ννλ‘ λνλΌ μ μμ΅λλ€.
1) Const
const ν€μλλ C μΈμ΄μμ μ¬μ©λλ ν κ°μ§ λ°©λ²μΌλ‘, λ³μλ₯Ό μμλ‘ μ μΈνλ λ°μ μ¬μ©λ©λλ€. constλ₯Ό λ³μ μ μΈ μμ λΆμ΄λ©΄, ν΄λΉ λ³μλ κ°μ λ³κ²½ν μ μλ μμκ° λ©λλ€.
2) κΈ°νΈ μμ(Symbolic Constant λλ 맀ν¬λ‘ μμ)
μ½λ λ΄μμ μ½κΈ° μ½κ³ μ μ§λ³΄μκ° μ©μ΄νλλ‘ μ΄λ¦μ λΆμ¬ν μμμ λλ€. #define μ μ²λ¦¬κΈ°λ₯Ό μ¬μ©νμ¬ μ μνλ©°, μΌλ°μ μΌλ‘ λλ¬Έμλ‘ μμ±λ©λλ€.
μΌλ°μ μΌλ‘ constλ₯Ό μ¬μ©νλ κ²μ΄ νμ μμ μ±μ΄λ μ½λ κ°λ μ± λ±μ μΈ‘λ©΄μμ λ κΆμ₯λλ©°, #defineμ μ£Όλ‘ λ§€ν¬λ‘λ μ‘°κ±΄λΆ μ»΄νμΌ λ± νΉλ³ν μν©μμ νμ©λ©λλ€.
3) 리ν°λ΄ μμ(Literal Constant)
μ½λμμ μ§μ λνλ΄λ μμμ λλ€. μλ₯Ό λ€μ΄, λ€μμ μ μμ λΆλ μμμ μμμ μμ λλ€.
- μ μ 리ν°λ΄: 10μ§μ, 8μ§μ, 16μ§μ λ±μ ννλ‘ ννλ©λλ€. μλ₯Ό λ€λ©΄ 10, 075, 0xA λ±μ΄ μμ΅λλ€.
- λΆλ μμμ 리ν°λ΄: μ€μλ₯Ό λνλ λλ€. μλ₯Ό λ€λ©΄ 3.14, 2.0e5 λ±μ΄ μμ΅λλ€.
- λ¬Έμ μμ: ν°&μμ λ°μ΄νλ‘ κ°μΈμ§ λ¬Έμλ₯Ό λνλ λλ€. μλ₯Ό λ€λ©΄ "A"(λ¬Έμμ΄), 'b'(λ¬Έμ) λ±μ΄ μμ΅λλ€.
A constant is a value that cannot be altered or modified during the execution of a program. Constants in C can be classified into various types, including literal constants and symbolic constants.
Literal constants are values directly written in the code, such as integers, floating-point numbers, and characters.
Symbolic constants are variables declared with the const keyword, indicating that their values cannot be changed once assigned.
#define is also used to define macros, which are small code snippets that are expanded inline wherever they are used in the code. Macros can be simple or complex, and they are often used to create reusable pieces of code.
While both const and #define can be used to create constants, they have some differences. const is a variable with a memory location, and its use is type-safe, whereas #define performs direct text substitution, which can lead to issues if not used carefully. In modern C programming, const is often preferred over #define for creating constants due to its type safety and better integration with the language's scoping rules. Macros defined using #define are still widely used for other purposes, such as code abstraction and conditional compilation.
β» GDB(GNU Debugger)λ GNU νλ‘μ νΈμ μΌλΆλ‘ κ°λ°λ λλ²κΉ λꡬλ‘, νλ‘κ·Έλ¨μ μ€ν μ€μ μ€λ₯λ₯Ό μ°Ύκ³ μμ νλ λ° μ¬μ©λ©λλ€. C, C++, Ada, Objective-C λ±μ νλ‘κ·Έλλ° μΈμ΄λ‘ μμ±λ νλ‘κ·Έλ¨μ λλ²κΉ νλ λ°μ μ£Όλ‘ μ¬μ©λ©λλ€.
GDBλ₯Ό κ΅³μ΄ μ¬μ©νλ μ΄μ λ μλ² λλ 리λ μ€ νκ²½μ ν¬λ‘μ€ gdbλ§ μ§μλλ κ²½μ°κ° μκΈ° λλ¬Έμ λλ€.
'Programming > C language' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
6 scanf ν¨μ (feat. format specifiers) (0) | 2024.01.23 |
---|---|
5 Operator (1) | 2024.01.23 |
3 Variable (0) | 2024.01.22 |
2 Hello world (0) | 2024.01.22 |
1 C language - Why do we learn it (0) | 2024.01.22 |
λκΈ