A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 1213842165 中级黑马   /  2015-11-13 22:45  /  1504 人查看  /  13 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

/*typedef*/
#include <stdio.h>
typedef long int Lint;

//结构体
typedef struct Person{
    char *name;
    int age;
} StPerson;



//数组
//typedef int  arr [5];

//这种方式定义:既可以用类型本身的方式,也可以用别名的方式定义.
typedef enum Status{
    NO,
    YES,
} eStatus;

//这种只能用别名的方式
typedef enum{
    WRONG,
    RIGHT,
} eStatus1;

#define  Lint1 long int

#define String char *

typedef char * str;

int main(){

   
    //基本数据类型
    Lint a=10;
    printf("%ld\n",a);
   
    //结构体
    //struct Person per={"张三",20};
    StPerson per={"张三",20};
    printf("name=%s,age=%d\n",per.name,per.age);
   
    //指针
    char *name="heima";
    str name1="heima";
    printf("%s---%s\n",name,name1);
   
    //数组
//    int arr0[5]={1,2,3,4,5};
//    arr arr1={1,2,3,4,5};
//   
//    for (int i=0; i<5; i++) {
//        printf("%d\n",arr1[i]);
//    }

   
    //定义在函数内
    typedef int  arr [5];
    arr arr1={1,2,3,4,5};
    for (int i=0; i<5; i++) {
            printf("%d\n",arr1[i]);
      }
   
   
    //枚举
    eStatus es=YES;
    enum Status es1=NO;
    printf("es=%d,es1=%d\n",es,es1);
   
   
    //这个时候typedef与宏定义可以互换
    Lint1 b=15;
    printf("b=%ld\n",b);
   
   
    /*
     宏定义可以实现一些typedef的功能,但是不能完全替换,
     因为typedef本自具有类型的含义.这是二者最大的区别.
    */
   
    //char *s1,s2;//这个表示:s1是指针类型,但是s2是char类型
    String s1,s2;//宏定义的方式
    s1="hello";
    s2='a';
    printf("%s---%c\n",s1,s2);
   
    str s3,s4;//typedef的方式
    s3="hello";
    s4="你好";
    printf("%s---%s\n",s3,s4);
   
    eStatus1 es2=WRONG;
    printf("es2=%d\n",es2);
   
    return 0;
}



13 个回复

倒序浏览
这个不错..
回复 使用道具 举报
挺好的,看完之后这些知识点又过了一遍。
回复 使用道具 举报
jy00889669 来自手机 中级黑马 2015-11-14 00:32:23
板凳
一看就是咱们班的,哈哈
回复 使用道具 举报
865393462 来自手机 中级黑马 2015-11-14 00:52:01
报纸
huihui1030 发表于 2015-11-14 00:12
挺好的,看完之后这些知识点又过了一遍。

搞的像你看过似的
回复 使用道具 举报
顶一个   今天的笔记啊  哈哈  你懂得
回复 使用道具 举报
都是C语言的交流啊,怎么没有OC?
回复 使用道具 举报
gabriel2016 发表于 2015-11-14 12:54
都是C语言的交流啊,怎么没有OC?

很快就有了
回复 使用道具 举报 1 0
cube川 中级黑马 2015-11-14 22:18:44
9#
宏定义只是单纯的替换。。。
回复 使用道具 举报
453702877 来自手机 中级黑马 2015-11-14 22:30:02
10#
任性的代码程序啊,66666666
回复 使用道具 举报
默默点赞!!!!!!!!!!!!!
回复 使用道具 举报
不错,不错,不错
回复 使用道具 举报

( ̄▽ ̄)"呵呵
回复 使用道具 举报

oc的话大部分就是加一个NS前缀
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马