Navigation

    GitHub中文社区
    • GitHub排行榜

    论坛

    • Login
    • Categories
    • Recent
    • Tags
    • Popular

    初识C语言

    综合交流
    1
    1
    304
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • shuang-ling
      shuang-ling last edited by

      #include<stdio.h>

      //#define MAX 100

      //#define MAX(X,Y) (X>Y?X:Y)

      //int main()
      //{
      // int a = MAX;
      // printf("%d",a);
      //
      //}

      //|| &&逻辑或和逻辑与

      //int main()
      //{
      // int a=0;
      // int b=3;
      // int max = 0;
      // max=(a>b?a:b);
      // printf("%d\n",max);
      // return 0;
      //}

      //int main()
      //{
      // int a=0;
      // int arr[]={1,2,3,4,5};
      //
      // printf("%d\n",sizeof a);
      // printf("%d\n",sizeof(arr));
      // printf("%d\n",sizeof(arr)/sizeof(arr[0]));
      //
      // return 0;
      //}

      //int main()
      //{
      // int a=10;
      // int b=a++;
      // printf("%d\n",a);
      // printf("%d\n",b);
      // return 0;
      //}

      //int Add(int x ,int y)
      //{
      // int z=0;
      // z=x+y;
      // return z;
      //}
      //int main()
      //{
      // int arr[10]={0};//[]下表引用操作符
      // int a = 10;
      // int b = 20;
      // int sum = Add(a,b);//()函数调用操作符
      // return 0;
      //}

      //int main()
      //{
      // typedef unsigned int u_int;//类型定义
      // unsigned int num = 20;// 相当于 u_int num2=20
      //}

      //void test()
      //{
      // static int a = 1;//static修饰局部变量,局部变量生命周期延长,出了作用域不再销毁
      // printf("a=%d\n",++a);
      //}
      //
      //int main()
      //{
      // int i = 0;
      // while (i<5)
      // {
      // test();
      // i++;
      // }
      //}

      //int main()
      //{
      // extern int g_val;//extern声明外部符号,但是如果在另外一个源文件中声明变量前加static,
      // //改变了变量的作用域,静态的全局变量只能在自己所在的源文件内部使用,此处无法调用
      // //extern 亦可声明外部函数 static修饰函数改变函数的链接属性,使其外部链接属性变为内部
      // printf("g_val = %d\n",g_val);
      // return 0;
      //}

      //int main()
      //{
      // int a=10;
      // int* p = &a;
      // *p = 20;
      // printf("%p\n",&a);
      // printf("%p\n",p);
      // printf("%d\n",a);
      //
      //}

      //int main()
      //{
      // char ch = 'w ' ;
      // char* pc = &ch;//pc的类型是char*,*告诉我们pc是一个指针变量,pc指向的对象是char类型
      // pc = 'a';// - 解引用操作符/间接访问操作符,操作的不是pc,而是ch
      // printf("%c",ch);
      // return 0;
      //}

      //int main()
      //{
      // double d = 3.14;
      // double* pd = &d;
      // printf("%d\n",sizeof(char*));
      // printf("%d\n",sizeof(int*));
      // //指针变量在同一个平台大小都相同,32位平台都是4字节,64位平台都是8
      // *pd = 5.5;
      // printf("%lf\n",d);// 相当于 printf("%lf\n",*pd)
      //
      //}

      #include<stdio.h>

      struct Book //创建一个结构体类型
      {
      char name[20];//C语言
      short price;//55
      };//注意分号
      int main()
      {
      struct Book b1 ={"C语言程序设计",55} ;//利用结构体类型创建一个该类型的结构体变量
      strcpy(b1.name,"C++");//string copy-字符串拷贝 把"C++"拷贝到b1.name里
      //struct Book* pb = &b1;
      //printf("%s\n",(*pb).name);// . 结构体变量.成员
      //printf("%s\n",pb->name); // -> 结构体指针->成员
      printf("书名:%s\n",b1.name);
      /printf("价格:%d\n",b1.price);
      b1.price = 15;
      printf("修改后的价格:%d\n",b1.price);
      /
      return 0;
      }

      1 Reply Last reply Reply Quote 0
      • First post
        Last post