C Tutorial/Preprocessor/define

Материал из C\C++ эксперт
Версия от 13:31, 25 мая 2010; Admin (обсуждение | вклад) (1 версия: Импорт контента...)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Use #define to define constant

<source lang="cpp">#include <stdio.h>

  1. define TRUE 1
  2. define FALSE 0
  3. define BS "\b"
  4. define TAB "\011"

main(){

  printf("%d",TRUE);
  printf("%d",FALSE);
  printf("%c",BS);
  printf("%d",TAB);

}</source>

19

Use preprocessor to define integer and string

<source lang="cpp">#include <stdio.h>

  1. define VAL 35
  2. define HELLO "HELLO"

main () {

   int res;
   res = VAL-5;
   printf ("res = VAL-5: res == %d\n", res);
   printf ("%s",HELLO);

}</source>

res = VAL-5: res == 30
      HELLO