C語言中的變數和關鍵字
變數
在 C 語言中,變數是用於儲存某種形式資料的儲存位置。不同的變數需要不同的記憶體量,並在其上應用一組操作。
變數名不能以數字開頭。它可以由字母、數字和下劃線“_”組成。
以下是 C 語言中宣告變數的語法:
type variable_name;
以下是 C 語言中宣告多個變數的語法:
type variable_name1, variable_name2,variable_name3;
以下是 C 語言中變數的一個示例:
示例
#include <stdio.h>
int main() {
char a1 = 'H';
int b = 90, c = 150;
float _d = 3.4;
printf("Character value : %c
",a1);
printf("Integer value : %d\t%d
",b,c);
printf("Float value : %f",_d);
return 0;
}輸出
Character value : H Integer value : 90150 Float value : 3.400000
關鍵字
關鍵字是 C 語言中預定義的保留字,每個關鍵字都與特定的功能相關聯。這些詞語幫助我們使用 C 語言的功能。它們對編譯器具有特殊含義。
C 語言中共有 32 個關鍵字。
| auto | double | int | struct |
| break | else | long | switch |
| case | enum | register | typedef |
| char | extern | return | union |
| continue | for | signed | void |
| do | if | static | while |
| default | goto | sizeof | volatile |
| const | float | short | unsigned |
以下是 C 語言中關鍵字的一個示例:
示例
#include <stdio.h>
int main() {
// char, int and float are keywords and used as datatypes
char c = 'H';
int b = 6, c;
float _d = 7.6;
// if and else is a keyword checking the value of b
if(b<5)
printf("Character Value : %c",a1);
else
printf("Float value : %f",_d);
return 0;
}輸出
Float value : 7.600000
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP