• 打印当前的C语言开发环境中各种基本类型的变量所占字节数及其可表示的最大值


    源文件main.c

     1 #include <stdio.h>
     2 
     3 #include <limits.h>
     4 #include <float.h>
     5 
     6 #include <string.h>
     7 
     8 void printLine() {
     9     printf("--------------------------------------
    ");
    10 }
    11 
    12 int main(void) {
    13     printf("sizeof(short) = %llu
    ", sizeof(short)); // 2
    14     printf("sizeof(int) = %llu
    ", sizeof(int)); // 4
    15     printf("sizeof(long) = %llu
    ", sizeof(long)); // 4
    16     printf("sizeof(long long) = %llu
    ", sizeof(long long)); // 8
    17     printLine();
    18     printf("sizeof(float) = %llu
    ", sizeof(float)); // 4
    19     printf("sizeof(double) = %llu
    ", sizeof(double)); // 8
    20     printf("sizeof(long double) = %llu
    ", sizeof(long double)); // 8
    21     printLine();
    22     printf("sizeof(char *) = %llu
    ", sizeof(char *)); // 4(x86:32bit) or 8(x64:64bit)
    23     printLine();
    24     printf("FILENAME_MAX = %u
    ", FILENAME_MAX);
    25     printLine();
    26     printf("CHAR_MAX = %d
    ", CHAR_MAX);
    27     printf("SHRT_MAX = %d
    ", SHRT_MAX);
    28     printf("INT_MAX = %d
    ", INT_MAX);
    29     printf("LONG_MAX = %ld
    ", LONG_MAX);
    30     printf("LLONG_MAX = %lld
    ", LLONG_MAX);
    31     printLine();
    32     printf("UCHAR_MAX = %u
    ", UCHAR_MAX);
    33     printf("USHRT_MAX = %u
    ", USHRT_MAX);
    34     printf("UINT_MAX = %u
    ", UINT_MAX);
    35     printf("ULONG_MAX = %lu
    ", ULONG_MAX);
    36     printf("ULLONG_MAX = %llu
    ", ULLONG_MAX);
    37     printLine();
    38     printf("FLT_MAX = %e
    ", FLT_MAX);
    39     printf("DBL_MAX = %le
    ", DBL_MAX);
    40     printf("LDBL_MAX = %Le
    ", LDBL_MAX);
    41     printLine();
    42     char array[] = "I Miss You so much!";
    43     printf("char array[1024] = "I Miss You so much!";
    ");
    44     printf("sizeof(array) = %llu
    ", sizeof(array));
    45     printf("strlen(array) = %llu
    ", strlen(array));
    46     printLine();
    47     char *array_pointer = "I Miss You so much!";
    48     printf("char *array_pointer = "I Miss You so much!";
    ");
    49     printf("sizeof(array_pointer) = %llu
    ", sizeof(array_pointer));
    50     printf("strlen(array_pointer) = %llu
    ", strlen(array_pointer));
    51     printLine();
    52     int i;
    53     for (i = 0; i < strlen(array); ++i) {
    54         printf("array[%02d] = %c
    ", i, array[i]);
    55     }
    56 
    57     return 0;
    58 }

    下面是在64位Windows 10上的Visual Studio 2017中编译运行的结果

  • 相关阅读:
    CocoStudio基础教程(4)骨骼动画的动态换肤
    CocoStudio基础教程(3)在程序中处理cocoStudio导出动画
    CocoStudio基础教程(2)关联程序逻辑与cocoStudio导出文件
    CocoStudio基础教程(1)创建UI并载入到程序中
    LeetCode:盛最多水的容器【11】
    LeetCode:反转字符串中的元音字母【345】
    LeetCode:验证回文串【125】
    LeetCode:颜色分类【75】
    LeetCode:删除排序数组中的重复项||【80】
    LeetCode:移动零【283】
  • 原文地址:https://www.cnblogs.com/yawenunion/p/8963497.html
Copyright © 2020-2023  润新知