Monday 27 July 2020

Keywords in C Programming

Like every computer language, C has a set of reserved words often known as keywords that can't be used as identifiers. All keywords are basically a sequence of characters that have a fixed meaning. By convention all keywords must be written in lowercase letters.
  1. There are totally 32 keywords in C language.
  2. Can't be used as Variable names.
  3. All keywords are in lowercase letter.
  4. Also called as reserved words.

Defines a local variable as having a local lifetime.

Keyword auto uses the following syntax:

[auto] data-definition;
As the local lifetime is the default for local variables, auto keyword is extremely rarely used.


Passes control out of the compound statement.

The break statement causes control to pass to the statement following the innermost enclosing while, do, for, or switch statement.

The syntax is simply



Makes variable value or pointer parameter unmodifiable.

When const is used with a variable, it uses the following syntax:

const variable-name [ = value];

In this case, the const modifier allows you to assign an initial value to a variable that cannot later be changed by the program. For example,

const my_age = 32;


Passes control to the beginning of the loop.

continue causes control to pass to the end of the innermost enclosing while, do, or for statement, at which point the loop continuation condition is re-evaluated. The syntax is simply



Do-while loop.

Keyword do is usually used together with while to make another form of repeating statement. Such form of the loop uses the following syntax:

do statement while (expression)
statement, which is usually a compound statement, is executed repeatedly as long as the value of expression remains non-zero. The test takes place after each execution of the statement.


Defines a set of constants of type int.

The syntax for defining constants using enum is

enum [tag] {name [=value], ...};

The set can optionally be given a type tag name with tag. name is the name of a constant that can optionally be assigned the (constant) value of value, etc. For example,

enum Numbers {One = 1, Two = 2, Three = 3, Four = 4, Five = 5};

If value is missing, then a value is assumed to be the value of the previous constant in the list + 1. If this is the first constant in the list, the default value is 0.

If you give a type tag name, then you can declare variables of enumerated type using

enum tag variable-names;

For example,

enum Numbers x, y, z;

declares three variables x, y and z, all of type Numbers (they are, in fact, integer variables). More precise, 'enum tag' becomes a new type which is equal in rights with any built-in type.


Indicates that an identifier is defined elsewhere.

Keyword extern indicates that the actual storage and initial value of a variable, or body of a function, is defined elsewhere, usually in a separate source code module. So, it may be applied to data definitions and function prototypes:

extern data-definition;
extern function-prototype;

For example,

extern int _fmode;
extern void Factorial (int n);

The keyword extern is optional (i.e. default) for a function prototype.

float, double

Floating point data types.

The keyword float usually represents a single precision floating point data type, and double represents a double precision floating point data type.


For loop.

For-loop is yet another kind of loop. It uses for keyword, with the following syntax:

for ([expr1]; [expr2]; [expr3]) statement
statement is executed repeatedly until the value of expr2 is 0. Before the first iteration, expr1 is evaluated. This is usually used to initialize variables for the loop. After each iteration of the loop, expr3 is evaluated. This is usually used to increment a loop counter.


Unconditionally transfer control.

goto may be used for transferring control from one place to another. The syntax is:

goto identifier;
Control is unconditionally transferred to the location of a local label specified by identifier.

if, else

Conditional statement.

Keyword if is used for conditional execution. The basic form of if uses the following syntax:

if (expression)

Alternatively, if may be used together with else, using the following syntax:

if (expression)
If expression is nonzero when evaluated, then statement1 is executed. In the second case, statement2 is executed if the expression is 0.

int, char

Basic data types (integer and character).

Variables of type int are one machine-type word in length.


Tells the compiler to store the variable being declared in a CPU register.

In standard C dialects, keyword auto uses the following syntax:

register data-definition;

The register type modifier tells the compiler to store the variable being declared in a CPU register (if possible), to optimize access. For example,

register int i;


Exits the function.

return exits immediately from the currently executing function to the calling routine, optionally returning a value. The syntax is:

return [expression];

For example,

int sqr (int x)
  return (x*x);

short, long, signed, unsigned

Type modifiers.

A type modifier alters the meaning of the base type to yield a new type. Each of these type modifiers can be applied to the base type int. The modifiers signed and unsigned can be applied to the base type char. In addition, long can be applied to double.


Returns the size of the expression or type.

Keyword sizeof is, in fact, an operator. It returns the size, in bytes, of the given expression or type (as type size_t). Its argument may be an expression of a type name:

sizeof expression
sizeof (type)


Preserves variable value to survive after its scope ends.

Keyword static may be applied to both data and function definitions:

static data-definition;
static function-definition;


Groups variables into a single record.

The syntax for defining records is:

struct [struct-type-name] { [type variable-names] ; ... } [structure-variables] ; A struct, like an union, groups variables into a single record. The struct-type-name is an optional tag name that refers to the structure type. The structure-variables are the data definitions, and are also optional. Though both are optional, one of the two must appear.

switch, case, default

Branches control.

switch causes control to branch to one of a list of possible statements in the block of statements. The syntax is

switch (expression) statement

The statement statement is typically a compound statement (i.e. a block of statements enclosed in braces). The branched-to statement is determined by evaluating expression, which must return an integral type. The list of possible branch points within statement is determined by preceding substatements with

case constant-expression :

where constant-expression must be an int and must be unique.

Once a value is computed for expression, the list of possible constant-expression values determined from all case statements is searched for a match. If a match is found, execution continues after the matching case statement and continues until a break statement is encountered or the end of statement is reached. If a match is not found and this statement prefix is found within statement,

default :


Creates a new type.

The syntax for defining a new type is

typedef type-definition identifier;
This statement assigns the symbol name identifier to the data type definition type-definition.


Groups variables which share the same storage space.

A union is similar to a struct, except it allows you to define variables that share storage space. The syntax for defining unions is:

union [union-type-name]
    type variable-names;
  } [union-variables] ;

For example,

union short_or_long
    short i;
    long l;
  } a_number;
The compiler will allocate enough storage in a number to accommodate the largest element in the union. Elements of a union are accessed in the same manner as a struct.


Empty data type.

When used as a function return type, void means that the function does not return a value. For example,

void hello (char *name)
  printf("Hello, %s.", name);


Indicates that a variable can be changed by a background routine.

Keyword volatile is an extreme opposite of const. It indicates that a variable may be changed in a way which is absolutely unpredictable by analysing the normal program flow (for example, a variable which may be changed by an interrupt handler). This keyword uses the following syntax:

volatile data-definition;

Every reference to the variable will reload the contents from memory rather than take advantage of situations where a copy can be in a register.


Repeats execution while the condition is true.

Keyword while is the most general loop statemens. It uses the following syntax:

while (expression) statement
statement is executed repeatedly as long as the value of expression remains nonzero. The test takes place before each execution of the statement.



Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning



Java Tutorial




C Programming


Python Tutorial


Data Structures


computer Organization