(第一天)object-c枚举和结构体

来源:互联网 发布:linux syslog server 编辑:程序博客网 时间:2024/05/19 10:14

在object-c中枚举的类型只能是整形比如int long short bool(true和false本质上是1和0)等。

struct结构体中的数据不能赋初值,所以赋值只能通过声明加入的方式。

#import <Foundation/Foundation.h>enum sex{    male=0,    female=1};typedef enum{    c=3,    d=4}test2;struct student {    char* name;    enum sex sex;    int age;};typedef struct student stu;int main(int argc, const char * argv[]){    stu su;    su.name="wen";    su.sex=male;    NSLog(@"name=%s,sex=%d",su.name,su.sex);    @autoreleasepool {                // insert code here...        NSLog(@"Hello, World!");            }    return 0;}


原创粉丝点击