1. 程式人生 > >C語言復習1_變量與數據類型

C語言復習1_變量與數據類型

info otl card tro 復習 精度 char double printf

變量命名規則:

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; }

C語言復習1_變量與數據類型