Android 下 JNI 开发

本文深入解析C语言中的枚举类型及结构体指针的应用,包括枚举值的递增特性、自定义数据类型的typedef使用,以及结构体指针的基本操作和成员访问方法。

19、枚举-3

enum WeekDay {

     Monday=0,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday

};

 

main() {

       enum WeekDay day = Sunday;

       printf("%d\n",day);

       system("pause");

}

枚举中的值是递增的。

枚举默认是从0开始

 

20、Typedef别名-4

声明自定义数据类型,配合各种原有数据类型来达到简化编程的目的的类型定义关键字。

在计算机编程语言中用来为复杂的声明定义简单的别名;

#include <stdio.h>

#include <stdlib.h>

typedef int i;

typedef long l;

main() {

       i m = 10;

       l n = 123123123;

       printf("%d\n", m);

       printf("%ld\n", n);

       system("pause");      

}

 

21、结构体指针-10

#include<stdio.h>

#include<stdlib.h>

/**

结构体指针

*/

 

//定义一个结构体

struct Student{

       int age;

       float score;

       char  sex;      

}       

main()

{      //结构体

      struct Student stu = {20,88.5,'W'};

      printf("stu.age=%d\n",stu.age);

 

      //结构体指针

      struct Student* stuPoint;

      //赋地址值

      stuPoint = &stu;

      //取值  (*stuPoint).age     

      printf("(*stuPoint).age=%d\n",(*stuPoint).age);

      //赋值 (*stuPoint).age =80;

 

      //另外一种取值 (*stuPoint).等价于 stuPoint-> 例如:

      //(*stuPoint).age 等价于 stuPoint->age

      printf("stuPoint->age=%d\n",stuPoint->age);

      system("pause");    

}    

 

运行结构如下:

 

 

(*stuPoint).age 等价于 stuPoint->age

 

 

 

本教程由尚硅谷教育大数据研究院出品,如需转载请注明来源。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值