大众计算机学习网

专门提供各种电脑教程

C语言register和#define命令用法

Admin | 2008-1-13 13:38:26 | 被阅次数 | 7279

  一、学习使用register定义变量的方法

  程序源代码:
  void main()
  {
  register int i;
  int tmp=0;
  for(i=1;i<=100;i++)
  tmp+=i;
  printf("The sum is %d\n",tmp);
  }

  二、宏#define命令练习

  程序源代码:
  #include "stdio.h"
  #define TRUE 1
  #define FALSE 0
  #define SQ(x) (x)*(x)
  void main()
  {
  int num;
  int again=1;
  printf("\40: Program will stop if input value less than 50.\n");
  while(again)
  {
  printf("\40lease input number==>");
  scanf("%d",&num);
  printf("\40:The square for this number is %d \n",SQ(num));
  if(num>=50)
   again=TRUE;
  else
   again=FALSE;
  }
  }