Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
孊ぶ Symbolic Constant | Macros
C Preprocessing

Symbolic Constant

メニュヌを衚瀺するにはスワむプしおください

Each #define line consists of three parts:

The body of a macro can be not only a single numeric value, but also other macros or entire expressions:

main.c

main.c

12345678910
#include <stdio.h> #define TWO 2 // macros with value. #define RESULT TWO*TWO // TWO is replaced by the number 2. #define PRINT printf("result = %d", RESULT); int main() { PRINT return 0; }

Every time the compiler encounters “TWO”, it will simply substitute its value 2.

The macro is immutable. Once defined, it is a permanent textual substitution within the file or scope where it is defined.

Why do we need this? Why not just use variables?

What is better to use?:

  • If the value never changes, const is better, because it is safer;
  • If you need to substitute a simple number or text, you can use a macro.
  1. Create an object macro add, the body of the macro is an addition operator +.
  2. Use a macro to add any two numbers.
タスク

スワむプしおコヌディングを開始

  1. Create an object macro add, the body of the macro is an addition operator +;
  2. Use a macro to add any two numbers.

解答

Switch to desktop実践的な緎習のためにデスクトップに切り替える䞋蚘のオプションのいずれかを利甚しお、珟圚の堎所から続行する
すべお明確でしたか

どのように改善できたすか

フィヌドバックありがずうございたす

セクション 2. 章 1
single

single

AIに質問する

expand

AIに質問する

ChatGPT

䜕でも質問するか、提案された質問の1぀を詊しおチャットを始めおください

some-alt