关键字是在C++库中预定义或保留的单词,具有固定的含义,并用于执行内部操作。C++语言支持超过64个关键字。
每个关键字都以小写字母形式存在,如auto、break、case、const、continue、int等。
C++语言中的32个关键字也可在C语言中使用。
autodoubleintstructbreakelselongswitchcaseenumregistertypedefcharexternreturnunionconstfloatshortunsignedcontinueforsignedvoiddefaultgotosizeofvolatiledoifstaticwhile
这是C++中新增的30个保留字,不在C语言中。
asmdynamic_castnamespacereinterpret_castboolexplicitnewstatic_castcatchfalseoperatortemplateclassfriendprivatethisconst_castinlinepublicthrowdeletemutableprotectedtruetrytypeidtypenameusingusingusingwchar_t
Input: str=”for”Output: for is a keyword
登录后复制
Explanation
关键字是程序中不能用作变量名的保留字。
C编程语言中有32个关键字。
将字符串与每个关键字进行比较,如果字符串相同,则字符串是关键字。
Example
示例
#include #include 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输出
which is a keyword登录后复制
以上就是检查给定字符串是否是关键字的C程序?的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2582942.html