W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
在標準ANSI C編程語言中定義了32個詞作為關(guān)鍵字。
這些關(guān)鍵字具有預定義的用途,不能用于C程序中的任何其他目的。
編譯器使用這些關(guān)鍵字。
關(guān)鍵詞 | 描述 |
---|---|
auto | 將局部變量定義為具有本地生存期 |
break | 將控制權(quán)從編程結(jié)構(gòu)中傳遞出去 |
case | 分支控制 |
char | 基本數(shù)據(jù)類型 |
const | 不可修改的值 |
continue | 控制循環(huán)開始 |
default | 分支控制 |
do | Do While循環(huán) |
double | 浮點數(shù)據(jù)類型 |
else | 條件語句 |
enum | 定義一組int類型的常量 |
extern | 表示其他地方定義的標識符 |
float | 浮點數(shù)據(jù)類型 |
for | For循環(huán) |
goto | 無條件地轉(zhuǎn)移程序控制 |
if | 條件語句 |
int | 基本數(shù)據(jù)類型 |
long | 類型修飾符 |
register | 將聲明的變量存儲在CPU寄存器中 |
return | 退出函數(shù) |
short | 類型修飾符 |
signed | 類型修飾符 |
sizeof | 返回表達式或類型大小 |
static | 在范圍結(jié)束后保留??變量值 |
struct | 將變量組成單個記錄 |
switch | 分支控制 |
typedef | 創(chuàng)建新類型 |
union | 組變量占用相同的存儲空間 |
unsigned | 類型修飾符 |
void | 空數(shù)據(jù)類型 |
volatile | 允許通過背景例程更改變量 |
while | 當條件為真時重復執(zhí)行程序 |
#include <stdio.h>
int main(void)
{
float fRevenue, fCost;
fRevenue = 0;
fCost = 0;
/* profit = revenue - cost */
printf("\nEnter total revenue: ");
scanf("%f", &fRevenue);
printf("\nEnter total cost: ");
scanf("%f", &fCost);
printf("\nYour profit is $%.2f\n", fRevenue - fCost);
return 0;
}
上面的代碼生成以下結(jié)果。
使用字符作為菜單選項。
#include <stdio.h>
int main(void)
{
char cResponse = "\0";
printf("\n\tAC Control Unit\n");
printf("\na\tTurn the AC on\n");
printf("b\tTurn the AC off\n");
printf("\nEnter your selection: ");
scanf("%c", &cResponse);
if (cResponse == "a")
printf("\nAC is now on\n");
if (cResponse == "b")
printf("\nAC is now off\n");
return 0;
}
上面的代碼生成以下結(jié)果。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: