zoukankan      html  css  js  c++  java
  • c语言,sizeof关键字,数组和指针区别

    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        char c = ' ';   //1 byte
        int a = 0;      //4 bytes
        long l = 100;   //4 bytes
        float f = 1.0;  //4 bytes
        int array[10];
        int *array_p = array;
        char *c_p = "abcdef";
        char c_array[] = "abcdef";
        printf("%d
    ", sizeof(array_p));    //pointer size, 4 bytes
        printf("%d
    ", sizeof(array));      //array size, 40 bytes
        printf("%d
    ", sizeof(c_p));        //pointer size, 4 bytes
        printf("%d
    ", sizeof(c_array));    //char array size, including the final char '', 7 bytes, different from function strlen, which ignoring the ending char ''
        return 0;
    }
    //从这里也可以看出数组和指针并非完全的等价
    //注意sizeof不是函数,属于关键字
  • 相关阅读:
    抽象工厂模式
    工厂方法模式
    单例模式
    适配器模式
    外观模式
    简单工厂模式
    设计模式开篇闲谈
    android ui更新
    android获取Context
    android 事件绑定
  • 原文地址:https://www.cnblogs.com/rocklee25/p/6895652.html
Copyright © 2011-2022 走看看