In C language, we have 32 Keywords, these keywords are predefined, reserved words used in programming that have special meanings to the compiler. It cannot be used as a variable name.
For example
/* Here, int is a keyword that indicates 'x' is a variable of Integer type. */
int x;
Since C is a case sensitive language, therefore all keywords must be written in lowercase. Here is a list of all keyword allowed in ANSI C.
Basic Description of these keywords:
auto: The auto keyword used to declare automatic variables.
For Example:
/* This statements indicates that 'x' is a variable of storage class auto and its type is int. */
auto int x;
This is the default storage class for all the variables declared inside a function or a block. Hence, variables declared within function bodies are automatic by default. the keyword auto is rarely used while writing programs in C language. Auto variables can be only accessed within the block/function
Note: A storage class defines the scope (visibility) and life-time of a variable and functions within a C Program.
break and Continue:
The break statement makes program jump out of the innermost enclosing loop (while, do, for or switch statements) explicitly.
The continue statement skips the certain statements inside the loop.
For Example:
for(i = 0; i <= 10; i++)
{
if (i == 3)
continue;
if (i == 7)
break;
printf ("%d", i);
}
Output
1, 2, 4, 5, 6
Description: As you can see in the above example, when i = 3; continue statement will come into effect and skip 3. And when i = 7; then break; statement will come into effect and terminates the for loop. To learn more visit break and continue statements in C.
switch, case and default:
The switch and case statements are used when we have number of options (or choices) and we may need to perform a different task for each choice.
For Example:
switch(expression)
{
case '1':
//some statements to execute when 1
break;
case '5':
//some statements to execute when 5
break;
default:
//some statements to execute when default;
}
char:
char keyword declare a character variable. To learn more visit data types in c. Have a look at the below example
/*Here 'c' is a character variable. To learn more visit data types in c.*/
char c;
const:
Variables can be declared as constant by using the 'const' keyword before the datatype of the variable. The default value of const variable is zero. To learn more visit literal and constant in C.
For Example:
/*Here 'x' is a constant variable of integer type.*/
const int x = 5;
do...while:
Syntax of do...while -> do {statements}; while(condition); Here, notice that the conditional expression appears at the end of the loop, so the do{statements}; in the loop will execute once before the condition is tested. If the condition is true, the flow of control jumps back to do, and the {statements} in the loop executes again.
For Example:
int i=1;
do
{
print("%d ",i);
i++;
}
while (i<10)
0 Comments:
Post a Comment
Please don't enter any spam link in the comment box.