關鍵字是在C 庫中預先定義或保留的單字,具有固定的含義,並用於執行內部操作。 C 語言支援超過64個關鍵字。
每個關鍵字都以小寫字母形式存在,如auto、break、case、const、continue、int等。
C 語言中的32個關鍵字也可在C語言中使用。
auto | double | int | struct |
break | else | long | switch |
#case | enum | register | typedef |
char | extern | return | union |
const | float | short | unsigned |
continue | ##for#signed | void | |
#goto | sizeof | volatile | |
if | static | while |
這是C 中新增的30個保留字,不在C語言中。
dynamic_cast | namespace | reinterpret_cast | |
explicit | new | static_cast | |
#false | operator | template | |
#friend | private | ##this | |
inline | public | #throw | |
#mutable | protected | true | |
typeid | ##typenameusing | using | |
wchar_t |
Input: str=”for” Output: for is a keyword
#include <stdio.h> #include <string.h> int main() { char keyword[32][10]={ "auto","double","int","struct","break","else","long", "switch","case","enum","register","typedef","char", "extern","return","union","const","float","short", "unsigned","continue","for","signed","void","default", "goto","sizeof","voltile","do","if","static","while" } ; char str[]="which"; int flag=0,i; for(i = 0; i < 32; i++) { if(strcmp(str,keyword[i])==0) { flag=1; } } if(flag==1) printf("%s is a keyword",str); else printf("%s is not a keyword",str); }###輸出###
which is a keyword###
以上是檢查給定字串是否是關鍵字的C程式?的詳細內容。更多資訊請關注PHP中文網其他相關文章!