
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C program to check if a given string is Keyword or not?
Keyword is a predefined or reserved word which is available in C++ library with a fixed meaning and used to perform an internal operation. C++ Language supports more than 64 keywords.
Every Keyword exists in lower case letters like auto, break, case, const, continue, int etc.
32 Keywords in C++ Language which is also available in the C language.
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 | volatile |
do | if | static | while |
These are 30 reserved words that were not in C, but added to C++
asm | dynamic_cast | namespace | reinterpret_cast |
bool | explicit | new | static_cast |
catch | false | operator | template |
class | friend | private | this |
const_cast | inline | public | throw |
delete | mutable | protected | true |
try | typeid | typename | using |
using | using | wchar_t |
Input: str=”for” Output: for is a keyword
Explanation
Keywords are reserved words which cannot be used as variable names in program.
There are 32 keywords in the C programming language.
Compare the string with each keyword if the string is same then string is keyword
Example
#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); }
Output
which is a keyword
- Related Articles
- Python program to check if a given string is Keyword or not
- Swift Program to check if a given string is Keyword or not
- How to check if a given word is a Python keyword or not?
- C# program to check if a string is palindrome or not
- C# program to check if string is panagram or not
- C# program to check whether a given string is Heterogram or not
- C++ program to check whether given string is bad or not
- Python - Check if a given string is binary string or not
- Python program to check if a string is palindrome or not
- Java Program to check if a string is empty or not
- Java program to check whether a given string is Heterogram or not
- Python program to check whether a given string is Heterogram or not
- Swift Program to check whether a given string is Heterogram or not
- Swift program to check if string is pangram or not
- Program to check given string is pangram or not in Python

Advertisements