结构体 理解

   地址:http://www.cnblogs.com/GarveyCalvin/p/4160077.html    说的很详细,很好。


   结构体其实就是自定义一个数据类型,如果结构体里面的变量也是结构体的话,也是支持用点符合获取下一级, 其中占用内存的就是里面定义的变量总和。

   下面是常用的结构表达形式, 其中结构体有3种形式。

   

   

#import <Foundation/Foundation.h>



@interface StructStu : NSObject
{
    
    struct  MyPoint{
        int  x;
        int  y;
        
    };
    struct  MyPoint  myPoint;
}

-(void) showMyPoint;
@end

#import "StructStu.h"

@implementation StructStu


-(void) showMyPoint{

    myPoint.x = 10;
    myPoint.y = 20;
    
    NSLog(@"x: %d   y:%d",myPoint.x,myPoint.y);

}

@end

StructStu  *myStruct = [[StructStu alloc] init];
        [myStruct showMyPoint];
        
        
        struct MyPoint myPoint = {200,3000}; // 初始化
        NSLog(@"x: %d    y:%d",myPoint.x,myPoint.y);


打印的结果如下


2015-01-06 23:08:49.451 OC基础学习[748:34315] x: 10   y:20

2015-01-06 23:08:49.452 OC基础学习[748:34315] x: 200    y:3000

Program ended with exit code: 0





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值