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 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
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:
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
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! ❤️