C语言摘要 -- K&R笔记(1)

最新文章请访问:https://shizhz.me/

本文是对《K&R》第二章 “Types, Operators, and Expressions” 的一个摘要。

开篇第一段,原样摘抄下来:

Variables andconstants are the basic data objects manipulated in a program.Declarations list the variables to be used, and state what type they have and perhaps what their initial values are.Operators specify what is to be done to them.Expressions combine variables and constants to produce new values. Thetype of an object determines the set of values it can have and what operations can be performed on it.

变量名:

1、变量名由字母(a-zA-Z)、数字(0-9)、与下划线(_)组成,头字母不能是数字;

2、变量名区分大小写;以下语句声明了两个不同的变量:

int x, X;

3、关键字例如if, else, switch等不能用于变量名;

4、变量长度:最好小于31个字符,长度限制取决于编译器,太长也不具备实际意义了。

数据类型:

1、char: 单字节,表示本地字符集中的一个字符,本质上说其值是该字符对应的整数值,所以char类型可直接用于算术运算;

2、int: 整数,short int: 简写为short, long int: 简写为long,可用sizeof操作符判断字节大小;

3、float:单精度浮点数;

4、double:双精度浮点数, long double:扩展精度浮点数;

5、修饰符signed与unsigned可用于修饰char及任何整型,区别是signed表示符号位;

#include <stdio.h>

int main (int argc, char const* argv[])
{
    printf("size of char: %d, short: %d, int: %d, long: %d, float: %d, double: %d, long double: %d\n", sizeof(char), sizeof(short), sizeof(int), sizeof(long), sizeof(float), sizeof(double), sizeof(long double));
    return 0;
}

本机结果:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值