Home  >  Article  >  Backend Development  >  What are the different types of keywords in C language?

What are the different types of keywords in C language?

PHPz
PHPzforward
2023-09-14 14:57:021446browse

What are the different types of keywords in C language?

Keywords are often called predefined or reserved words in programming languages. Each keyword in C language performs a specific function in the program.

  • Keywords cannot be used as variable names.

  • The keyword has a fixed meaning and this meaning cannot be changed.

  • They are the building blocks of 'C' programs.

  • C language supports 32 keywords.

  • All keywords are written in lowercase letters.

The different types of keywords are as follows:

auto double int struct
break else long switch
case enum register typedef
char extern return union
const short float unsigned
continue for signed void
default goto sizeof volatile
do if static while

Example

The following is a C program for a simple calculator written using Switch Case:

Demonstration

#include <stdio.h>
int main(){
   char Operator;
   float num1, num2, result = 0;
   printf("</p><p> Try to Enter an Operator (+, -, *, /) : ");
   scanf("%c", &Operator);
   printf("</p><p> Enter the Values for two Operands: ");
   scanf("%f%f", &num1, &num2);
   switch(Operator){
      case &#39;+&#39;: result = num1 + num2;
      break;
      case &#39;-&#39;: result = num1 - num2;
      break;
      case &#39;*&#39;: result = num1 * num2;
      break;
      case &#39;/&#39;: result = num1 / num2;
      break;
      default: printf("</p><p> entered operator is invalid ");
   }
   printf("</p><p> The result of %.2f %c %.2f = %.2f", num1, Operator, num2, result);
   return 0;
}

Output

When the above program is executed, it produces the following result −

Enter an Operator (+, -, *, /) : *
Enter the Values for two Operands: 34 12
The result of 34.00 * 12.00 = 408.00

In the above example, the keywords used to execute the simple calculator program are as follows:

Int , char, switch, case, break, float, default, return

These words cannot be used as variables when writing a program.

The above is the detailed content of What are the different types of keywords in C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete