• 2_C语言中的数据类型 (一)2.1.常量和字符串常量


    2.1 常量就是在程序中不可变化的量,常量在定义的时候必须给一个初值。

    1.1.1          #define

    定义一个宏常量

    1.1.2          const

    定义一个const常量

    2.2       字符串常量

    “hello world”

    对于#define类型的常量,c语言的习惯是常量名称为大写,但对于普通const常量以及变量,一般为小写结合大写的方式

    示例代码:

    #include<stdio.h>
    
    #define MAX 10  //定义一个宏常量,值为10
    #define STRING "hello world
    "  //定义了一个字符串常量
    
    int main()
    {
        int i;                  //定义一个变量,名字为i,值可变
        const int a     = 20;   //定义了一个const常量,值为20
        const char *str = "hello c";
        i = 100;
        i = 5;
        //MAX = 200; //常量的值不能修改
    
        //a = 0;         //常量的值不能修改
        printf(STRING);
        return 0;
    }
  • 相关阅读:
    linux commands ---2 ,学习vim编辑器如何使用的方法。
    $stateParams 详解
    ipa 打包遇到的坑
    原生和jQuery的ajax用法
    ios 的 desciption
    ios上线流程
    android 上线流程
    cordova 常用插件
    iframe
    cordova 强制竖屏
  • 原文地址:https://www.cnblogs.com/wuchuanying/p/6271159.html
Copyright © 2020-2023  润新知