⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap9.lst

📁 Borland C++ Builder The Complete Reference 例程源代码
💻 LST
字号:
listing 1
/* Will not work! */ 
#include <stdio.h>  #include <stdlib.h>

listing 2
#define UP 1 
#define DOWN 0

listing 3
printf("%d %d %d", DOWN, UP, UP+1);

listing 4
#define ONE   1 
#define TWO   ONE+ONE 
#define THREE ONE+TWO

listing 5
#define E_MS "Standard error on input.\n" 
/* ... */ 
printf(E_MS);

listing 6
printf("Standard error on input.\n");

listing 7
#define XYZ "this is a test" 
/* ... */ 
printf("XYZ");

listing 8
#define LONG_STRING "This is a very long \ 
string that is used as an example."

listing 9
#define MAX_SIZE 100 
/* ... */ 
float balance[MAX_SIZE]; 
/* ... */ 
float temp[MAX_SIZE];

listing 10
#include <stdio.h> 
 
#define MIN(a,b)  ((a)<(b)) ? (a) : (b) 
 
int main(void) 
{ 
  int x, y; 
 
  x = 10; 
  y = 20; 
  printf("The minimum is: %d", MIN(x, y)); 
 
  return 0; 
}

listing 11
printf("The minimum is: %d",((x)<(y)) ? (x) : (y));

listing 12
/* This program will give the wrong answer. */ 
 
#include <stdio.h> 
 
#define EVEN(a) a%2==0 ? 1 : 0 
 
int main(void) 
{ 
  if(EVEN(9+1)) printf("is even"); 
  else printf("is odd"); 
 
  return 0; 
}

listing 13
#include <stdio.h> 
 
#define EVEN(a) (a)%2==0 ? 1 : 0 
 
int main(void) 
{ 
  if(EVEN(9+1)) printf("is even"); 
  else printf("is odd"); 
 
  return 0; 
}

listing 14
#include "stdio.h" 
#include <stdio.h>

listing 15
/* The program file: */ 
#include <stdio.h> 
 
int main(void) 
{ 
  #include "one" 
 
  return 0; 
} 
 
 
 
/* Include file ONE: */ 
printf("This is from the first include file.\n"); 
#include "two" 
 
 
 
/* Include file TWO: */ 
printf("This is from the second include file.\n");

listing 16
/* A simple #if example. */ 
#include <stdio.h> 
 
#define MAX 100 
int main(void) 
{ 
#if MAX>99 
  printf("Compiled for array greater than 99.\n"); 
#endif 
  return 0; 
}

listing 17
/* A simple #if/#else example. */ 
#include <stdio.h> 
 
#define MAX 10 
int main(void) 
{ 
#if MAX>99 
  printf("Compiled for array greater than 99.\n"); 
#else 
  printf("Compiled for small array.\n"); 
#endif 
  return 0; 
}

listing 18
#define US 0 
#define ENGLAND 1 
#define FRANCE 2 
 
#define ACTIVE_COUNTRY US 
 
#if ACTIVE_COUNTRY==US 
  char currency[] = "dollar"; 
#elif ACTIVE_COUNTRY==ENGLAND 
  char currency[] = "pound"; 
#else 
  char currency[] = "franc"; 
#endif

listing 19
#if MAX>100 
   #if SERIAL_VERSION 
      int port = 198; 
   #elif 
      int port = 200; 
   #endif 
#else 
   char out_buffer[100]; 
#endif

listing 20
#if (sizeof(char *) == 2) 
  printf("Program compiled for small array."); 
#else 
  printf("Program compiled for large array."); 
#endif

listing 21
#include <stdio.h> 
 
#define TED 10 
 
int main(void) 
{ 
#ifdef TED 
  printf("Hi Ted\n"); 
#else 
  printf("Hi anyone\n"); 
#endif 
#ifndef RALPH 
  printf("RALPH not defined\n"); 
#endif 
  return 0; 
}

listing 22
#define LEN 100 
#define WIDTH 100 
 
char array[LEN][WIDTH]; 
 
#undef LEN 
#undef WIDTH 
/* at this point both LEN and WIDTH are undefined */

listing 23
#if defined MYFILE

listing 25
#if !defined DEBUG 
  printf("Final version!\n"); 
#endif

listing 26
#include <stdio.h> 
 
#line 100                    /* reset the line counter */ 
int main(void)               /* line 100 */ 
{                            /* line 101 */ 
  printf("%d\n", __LINE__);  /* line 102 */ 
 
  return 0; 
}

listing 27
void f(void);

listing 28
#include <stdio.h> 
 
void start(void); 
 
#pragma startup start 65 
 
int main(void) 
{ 
  printf("In main\n"); 
 
  return 0; 
} 
 
void start(void) 
{ 
  printf("In start\n"); 
}

listing 29
#include <stdio.h> 
 
#pragma message This will be displayed. 
 
int main(void) 
{ 
  int i=10; 
 
  printf("This is i: %d\n", i); 
#pragma message This is also displayed. 
  return 0; 
}

listing 30
#include <stdio.h> 
 
#define mkstr(s)  # s 
 
int main(void) 
{ 
  printf(mkstr(I like C++ Builder)); 
 
  return 0; 
}

listing 31
printf(mkstr(I like C++ Builder));

listing 32
printf("I like C++ Builder");

listing 33
#include <stdio.h> 
 
#define concat(a, b)  a ## b 
 
int main(void) 
{ 
  int xy = 10; 
 
  printf("%d", concat(x, y)); 
 
  return 0; 
}

listing 34
printf("%d", concat(x, y));

listing 35
printf("%d", xy);

listing 36
#include <stdio.h> 
 
int main(void) 
{ 
  printf("hello"); 
  /* printf("there"); */ 
 
  return 0; 
}

listing 37
x = 10+ /* add the numbers */5;

listing 38
swi/*this will not work*/tch(c) { ...

listing 39
/* this is an outer comment 
  x = y/a; 
  /* this is an inner comment - and causes an error */ 
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -