021. C语言基础

//   201.c
//带参数的宏代换
#include<stdio.h>
#define MAX(a,b) a>b?a:b
void main()
{
   int a=3,b=5;
   printf("%d",MAX(a,b));
   getch();
}
//  202.c
#include<stdio.h>
#define MUL(a,b) a*b
void main()
{
   int a=2,b=3;
   printf("%d",MUL(a+b,b-a));
   getch();
}
//    203.c
#include<stdio.h>
//条件编译,根据不一样的条件,实现不一样编译
#define M 0
void main()
{
   int a,b;
   scanf("%d%d",&a,&b);
   #if M
   printf("%d",a+b);
   #else
   printf("%d",a-b);
   #endif
   getch();
}
//   204.c
#include<stdio.h>
#define M
void main()
{
  int a,b;
  a=3;b=5;
  #ifdef M
  printf("%d",a+b);
  #else
  printf("%d",a-b);
  #endif
  getch();
}
//     205.c
#include<stdio.h>
#define M
void main()
{
  int a,b;
  a=3;b=5;
  #ifndef M
  printf("%d",a+b);
  #else
  printf("%d",a-b);
  #endif
  getch();
}
//    206.c
#include<stdio.h>
//定义结构体数据类型的方法
struct student
{
   int num;
   char name[20];
   char sex;
   int age;
   float score;
   char addr[20];
};
void main()
{
   struct student x={1,"xxx",'M',18,95.5,"zyzz-366"};
   printf("%s %f",x.name,x.score);//.就是成员运算符号。
   x.score=95.0;
   printf("\n%s %f",x.name,x.score);//.就是成员运算符号。
   getch();
}
//   207.c
#include<stdio.h>
//定义结构体数据类型的方法
struct student
{
   int num;
   char name[20];
   char sex;
   int age;
   float score;
   char addr[20];
};
struct student1
{  int num;
   char name[20];
   char sex;
   int age;
   float score;
   char addr[20];
};
void main()
{
   struct student x={1,"xxx",'M',18,95.5,"zyzz-366"};
   struct student1 y;
   y=x;//调试编译出错,必须保证两个变量的类型绝对一致。
   printf("%s %f",y.name,y.score);//.就是成员运算符号。
   getch();
}

//    208.c
#include<stdio.h>
//将结构体数据类型写在main函数的内部
//先类型后变量
void main()
{
   struct node
   {
      int a;
      char b;
   };
   struct node x;

}
//    209.c
#include<stdio.h>
//在定义类型的同时,去定义变量
void main()
{
   struct node
   {  int a;
      char b;
   }x;
}
//   210.c
#include<stdio.h>
void main()
{
   struct
   {
     int a;
     char b;
   }x;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容