C语言复习1_变量与数据类型

变量命名规则:

1、变量名的首字母或下划线(不能是其他特殊符号)

2、变量名的其他字母包含下划线、数字 和字母

3、不能使用关键字

基本数据类型

分为数值型和非数值型,其中数值型分为整型和非整型

整型分为int,short和long

非整型分为单精度float(小数点后位数少 )和双精度double(小数点后位数多)

非数值型有char

详细如下图:

声明变量:

int score totle;
short int studentNo;
long id_card

初始化变量:

score_totle = 590;
studentNo = 20;

举例:

#include <stdio.h>

int main()
{
    float height = 150.0f;
    float width = 25.0f;
    float s = height*width;
    printf("长方形的面积为:%.2f\n", s);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/yqpy/p/10367494.html