Keywords in C Programming Language | reserved keywords in c programming | define keywords in c programming | keywords in c programming examples
keywords in c programming examples
In C programming, keywords are reserved words with predetermined definitions that constitute a structural component of the language. They have special importance and are used for specialized reasons in the language, hence they cannot be used as identifiers (variable names, function names, etc.). Control structures, data types, function declarations, and other things are all defined by keywords.
Here are some examples of C programming keywords:
int: specifies the data type for integers.
float: specifies the data type for floating points.
char: the character data type is specified.
if, else: used in conditional expressions to carry out various actions in accordance with a condition.
for, while, do: used to repeat a chunk of code in loop constructions.
switch, case, default: used in switch-case statements to carry out various operations depending on various values.
return: used to have a function return a value.
void: Indicates that a data type or return value is not present.
const: declares a fixed-value variable known as a constant.
sizeof: gives the size of a data type or variable in bytes.
These keywords have established meanings and actions in the C programming language. It is crucial to remember that keywords are case-sensitive, which means the compiler will not identify them as keywords if they are used in a different case (for example, "IF," "Else").
Keywords cannot be used as identifiers in a C program since they have established meanings. To prevent compilation issues and confusion, it is advised to use variable and function names that do not clash with keywords.
What are the keywords in c programming
The following categories of keywords can be identified in C programming:
a. Storage Class Specifiers:
auto: Declares an automatic (local) variable.
extern: Declares an external variable or function.
register: recommends putting a variable in a CPU register to provide for quicker access.
static: Declares a static variable with a local or global scope.
Examples:
auto int x; // Automatic (local) variable
extern int count; // External variable
register int i; // Register variable
static int num; // Static variable
b. Data Types:
int: Represents integers.
float: Represents single-precision floating-point numbers.
double: Represents double-precision floating-point numbers.
char: Represents characters.
void: Represents the absence of a data type.
Examples:
int age; // Integer data type
float pi; // Single-precision floating-point data type
double salary; // Double-precision floating-point data type
char grade; // Character data type
void result(); // Function with no return value or arguments
c. Control Flow:
if, else: Conditional statements for decision making.
switch, case, default: Used for multi-way branching.
for: Looping construct with initialization, condition, and iteration.
while: Looping construct with a condition.
do, while: construct for looping with a condition check at the conclusion.
Examples:
if (score > 90) {
printf("Excellent!");
} else {
printf("Good!");
}
switch (choice) {
case 1:
printf("Option 1 selected.");
break;
case 2:
printf("Option 2 selected.");
break;
default:
printf("Invalid option.");
}
while (num > 0)
{
printf("%d ", num);
num--;
}
do {
printf("%d ", i);
i++;
} while (i < 5);
d. Functions:
return: Specifies the return value of a function.
void: declares that a function does not provide a value as a result.
Examples:
int add(int a, int b) {
return a + b;
}
void greet() {
printf("Hello!");
}
e. Modifier Keywords:
const: Declares a constant variable whose value cannot be changed.
volatile: Specifies that a variable can be modified by external factors.
unsigned: a variable can only retain positive values, according to its specification.
signed: Clearly states that a variable may have both positive and negative values.
Examples:
const int MAX_SIZE = 10; // Constant variable
volatile int sensorValue; // Volatile variable
unsigned int positiveNum; // Unsigned variable
signed int temperature; // Signed variable
f. Miscellaneous:
sizeof: Returns the size in bytes of a data type or variable.
enum: Declares an enumeration type.
struct, union: Declares user-defined composite data types.
typedef: Creates a new type alias.
These are the C programming language's most popular keywords. It's crucial to keep in mind that keywords are case-sensitive and cannot be used as program identifiers. It's critical to pick acceptable names for variables, functions, and other identifiers in order to prevent ambiguities with these keywords and guarantee the program will compile and run correctly.
Our Channel YouTube Video Watch Now !!!
Properties of Keywords:
- The C programming language defines every keyword as a lowercase letter, therefore this is the only case in which it may be used.
- Every keyword has a distinct meaning, which users cannot alter.
- In user-defined names for variables, functions, arrays, pointers, etc., keywords cannot be used.
- Every keyword in the C programming language either specifies an action to be taken by the compiler or symbolizes something.
COMMENTS