zoukankan      html  css  js  c++  java
  • iOS对象指针大小

    一个指针在32位的计算机上,占4个字节;一个指针在64位的计算机上,占8个字节。

    指针就是地址,地址就是指针。

    扩展:

        int a = 10;
        char b = 'b';
        short c = 2;
        long d = 9;
        float e = 6.29f;
        double f = 95.0629;
        int arr[] = { 1,2,3 };
        char arrB[] = { '1','2','3' };
        char str[] = "hello";
        double *p=&f;
        int *i=&a;
        NSString *string = @"hello world";
        //分别对各个变量使用sizeof运算
        NSLog(@"int_a=%d,char_b=%d,short_c=%d,long_d=%d,float_e=%d,double_f=%d,arr=%d,arrB=%d,str=%d,strlen=%d,point_p=%d,point_i=%d,point_string=%d",
            sizeof(a), sizeof(b), sizeof(c), sizeof(d), sizeof(e), sizeof(f),
              sizeof(arr), sizeof(arrB), sizeof(str), strlen(str), sizeof(p), sizeof(i), sizeof(string));

    结果:

    int_a=4,char_b=1,short_c=2,long_d=8,float_e=4,double_f=8,arr=12,arrB=3,str=6,strlen=5,point_p=8,point_i=8,point_string=8

    sizeof实际上是获取了数据在内存中所占用的存储空间,以字节为单位来计数。C语言会自动在在双引号""括起来的内容的末尾补上""代表结束,ASCII中的0号位也占用一个字符。

    int占4字节,字符占1字节,指针地址占8个字节

    strlen返回的是存储在数组中的字符串的长度,sizeof返回的是数组本身长度,如果没有声明数组大小,即strlen长度+''结尾

    问:假如,我们想通过CPU在内存中读取一个数字3,那么是怎样一个操作呢?

    首先,CPU通过地址总线,在内存中找到数字3的地址;

    然后,通过控制总线知道该操作是读还是写;

    然后,通过数据总线,把数字3传输到CPU中。

    在北京的灯中,有一盏是我家的。这个梦何时可以实现?哪怕微微亮。北京就像魔鬼训练营,有能力的留,没能力的走……
  • 相关阅读:
    codeforces 652B z-sort(思维)
    poj 3268 Silver Cow Party(最短路)
    POJ 2243:Knight Moves(BFS)
    POJ 1107:W's Cipher(模拟)
    POJ 1008 Maya Calendar(模拟)
    Hdu3436-Queue-jumpers(伸展树)
    主席树的另一种写法
    Hdu5785-Interesting(回文串处理)
    Hdu5008-Boring String Problem(后缀数组)
    RMQ模板
  • 原文地址:https://www.cnblogs.com/huangzs/p/14522742.html
Copyright © 2011-2022 走看看