typedef 定义(或者叫重命名)类型而不是变量

1、类型是一个数据模板,变量是一个实在的数据。类型是不占内存的,而变量是占内存的。

2、面向对象的语言中:类型的类class,变量就是对象。

#include<stdio.h>

//结构体类型的定义
// struct student
// {
// char name[20];
// int age;
// }; //定义一个结构体类型,这个类型有2个名
typedef struct student
{
char name[20];
int age;
} student; //第一个结构体类型 struct teacher, teacher;
//第二个结构体指针类型struct teacher *,pTeacher;
typedef struct teacher1
{
char name[20];
int age;
int mager;
}teacher, *pTeacher; int main(void)
{
student St1,St2;
teacher Tc1,Tc2; pTeacher Tc3,Tc4; Tc1.age = 11;
Tc3 = &Tc1; St1.age = 12;
printf("%d\n",Tc3->age);
}

  

typedef 加const的用法

#include<stdio.h>

typedef int *PINT;
typedef const int *CPINT;
//const int *p 和 int *const p是不同的。前者是p指向的变量是const,后者是p本身const int main(void)
{
int a = , b = , c = ;
PINT p1 = &a; const PINT p2 = &a;
CPINT p3 = &c; printf("*p1 = %d\n",*p1);
printf("*p2 = %d\n",*p2); *p2 = ;
printf("*p2 = %d\n",*p2); //*p3 = 88; //此语句出错,
p3 = &b;
printf("*p3 = %d\n",*p3); // PINT p2 = &b; //此语句出错
// printf("*p2 = %d\n",*p2);
}
/*
typedef int *PINT; const PINT p2;相当于int *const p2;
typedef int *PINT; PINT const p2;相当于int *const p2;
如果确实想得到const int *p;这种效果,只能typedef const int *CPINT;CPINT p1;
*/

最新文章

  1. Spring学习记录(三)---bean自动装配autowire
  2. Debugging into .NET Core源代码的两种方式
  3. 首师大附中互测题:99999999海岛帝国后传:算法大会【D001】
  4. android上引入七牛 上传图片或者文件 最终整理版本(可用)
  5. VS2010 asp.net development server 无法展示svg图片
  6. jquery selector checkbox
  7. Fiddler工具的基本功能
  8. openlayers加载百度地图
  9. Torry的困惑(基本型)
  10. 搜索(DLX重复覆盖模板):HDU 2295 Radar
  11. ListView中RadioButton实现单项选择
  12. 怎么写cookie
  13. .net使用RabbitMQ
  14. 使用open-falcon监控Nginx
  15. bzoj4361isn 容斥+bit优化dp
  16. HeadFirst设计模式读书笔记之策略模式
  17. SQLServer之创建非聚集索引
  18. 创建线程时如果既传入了runnable对象,又继承thread重写了run方法,会执行的哪里的代码
  19. js 函数中的this
  20. 测试那些事儿—postman进阶使用与实战

热门文章

  1. Django - 文件上传、Django组件 - 分页器(paginator)
  2. 48dp rhythm
  3. Java io流详解二
  4. 浅谈 JS 内存泄露方式与避免方法(二)
  5. go——通道
  6. ie9下面的console的bug
  7. Linux x86架构下ACPI PNP Hardware ID的识别机制
  8. Django 中间件简介
  9. Python面试题之Python和Java中Super方法的区别
  10. git报错--RPC failed; curl 18 transfer closed with outstanding read data remaining