Keywords and Identifiers

In the world of programming, every language has its own set of rules and words that are reserved for specific purposes. In C language, these reserved words are called Keywords, while Identifiers are user-defined names given to various program elements.

Keywords in C

Keywords are reserved words in the C language that have predefined meanings and cannot be used for any other purpose like variable names or function names. They play a crucial role in defining the syntax and structure of the C program.

keywords in C

  1. auto: Declares automatic variables.
  2. break: Exits from the loop or switch statement.
  3. case: Specifies a value for a particular condition in a switch statement.
  4. char: Declares a character type variable.
  5. const: Specifies that the value of a variable cannot be changed.
  6. continue: Jumps to the next iteration of the loop.
  7. default: Specifies the default condition in a switch statement.
  8. do: Initiates a do-while loop.
  9. double: Declares a double-precision floating-point variable.
  10. else: Specifies the alternative condition in an if statement.
  11. enum: Declares an enumeration type.
  12. extern: Declares a variable or function as external.
  13. float: Declares a floating-point variable.
  14. for: Initiates a for loop.
  15. goto: Transfers control to a labeled statement.
  16. if: Specifies a conditional statement.
  17. int: Declares an integer type variable.
  18. long: Declares a long integer type variable.
  19. register: Declares a register variable.
  20. return: Returns a value from a function.
  21. short: Declares a short integer type variable.
  22. signed: Declares a signed type variable.
  23. sizeof: Returns the size of a variable or data type.
  24. static: Declares a static variable or function.
  25. struct: Declares a structure type.
  26. switch: Initiates a switch statement.
  27. typedef: Defines a new data type.
  28. union: Declares a union type.
  29. unsigned: Declares an unsigned type variable.
  30. void: Specifies an empty type.
  31. volatile: Indicates that a variable may be changed externally.
  32. while: Initiates a while loop.

Identifiers in C

Identifiers are names given to various program elements such as variables, functions, arrays, etc. These names are created by the programmer and are used to identify and reference these elements throughout the program. Identifiers must adhere to certain rules:

  1. Must begin with a letter (uppercase or lowercase) or an underscore (_).
  2. Can be followed by letters, digits, or underscores.
  3. Cannot be a keyword.
  4. No special characters (except underscore) are allowed.
  5. Case sensitive.

Examples of valid identifiers

  • sum
  • total_count
  • variable123
  • _data
  • Name

Examples of invalid identifiers:

  • 123variable (starts with a digit)
  • break (keyword)
  • my-variable (contains a hyphen)
  • void (keyword)
  • my identifier (contains a space)
				
					#include <stdio.h>

int main() {
    // Declaring variables
    int num1, num2, sum;
    
    // Assigning values to variables
    num1 = 10;
    num2 = 20;
    
    // Performing addition
    sum = num1 + num2;
    
    // Displaying the result
    printf("Sum of %d and %d is %d\n", num1, num2, sum);
    
    return 0;
}

				
			

In this example, int, main, num1, num2, sum, printf, and return are all identifiers. int is a keyword used to declare integer variables, main is the name of the main function, and the rest are variable names and function names.

Understanding keywords and identifiers is essential for writing correct and efficient C programs. Keywords provide the basic building blocks of the language, while identifiers give programmers the ability to create meaningful names for variables, functions, and other elements in their code. By following the rules for identifiers and avoiding the use of keywords as identifiers, programmers can write clear and concise code that is easy to understand and maintain. Happy coding! ❤️

Table of Contents

Contact here

Copyright © 2025 Diginode

Made with ❤️ in India