C Language

Keywords in C programming Language

Keywords in C programming Language

In this tutorial , we will discuss keywords in C language

C language contains about 31 keywords. Keywords are already defined by compiler for reserve purpose. C language keywords are also called reserve words. Keywords can not be used as variable name


Explanation of keywords

 

1. autoThe auto keyword is used to declare a type of variable in the C Programming language. It is the automatic variable and it is always a local variable only. This variable is declared either inside block or main.

Syntex

auto int var;

Example


auto int a=10;


Program

Output

The value within block: 5
the value within main: 10

The auto variable cannot be a global variable.

Default value of auto varIable is garbage value.

2. break – the break statement is mostly used in for loop  and while loop.

,Do while loop and switch statements

Syntex

break;

Program

 

Output

value of num is : 0
value of num is : 1
value of num is : 2
value of num is : 3
value of num is : 4
exit from while loop

 

3. continue –  the break statement is mostly used in for loop,while loop do while and switch -case statements.

Syntex

continue;

Example


Output

1
2
3
4
6
7
8
9
10

4. switch and case – swith and case statements are used to execute a block code among multiple statements. likes if … else… if statements

Syntex

switch(expression)
{
case '1';
//some codes to execute when 1
break;
case '2';
//some codes to execute when 2
break;
....................
....................
case 'n';
//some codes to execute when n
break;

}
 

6. default – default is used to switch -case statements

Syntex

default;

7. char – The char keyword declares a character variable. – variable declaration

Syntex

char char_name='value';

Example

char alphabet='A';

8. const – cons is a keyword that assigns an initial value to the variable that cannot be changed by the programmer. – variable declaration.

Syntex

 

const variable_name=value;

 

Example

 

const my_age=22;

9. do – Do is a keyword in c which is commonly used  with do- while loop. It looks like other programming languages.

Syntex

 

do-while(expression)

 

Example

 

Output
1234

10. while while is a keyword in C language which is used to execute a loop statement. While statement executes repeatedly until statement becomes false

Syntex

 

while(expression)

 

Example

Output
1
2
3
4

11. double – double is a keyword in C language which is used to represents floating point value.

Syntex

double value;   - variable declaration

Example

double salary=23123.56;

12.float -float is a keyword in C language which is used to represents single precision floating point data type.  – variable declaration.

Syntex

float value;

Example

float average=67.7;

13. if –  if is a keyword in C language which is used for conditional statements execution. If evaluates expression and when it becomes true(nonzero), statement is executed.  Otherwise, when evaluation  becomes false(zero), statement of if is skipped.

The basic form syntex of if

Syntex

if(checkExpression)
statement1

14. else – If statements may be used together with else. When if statement becomes false(zero), else execute the statement.

Syntex

if(checkExpression)
statement1
else
statement2

Example

15.enumEnumeration (enum) is a keyword in C Language, which is used to declare user defined data type that consists of numerical value
Syntex

enum variable_name
{
constant 1,
constant 2,
constant 3,
}
Example

enum Week{

Sunday

Monday

Tuesday

wednesday

Thursday

Friday

Saturday }

16. extern –  extern keyword is used for declaring external variables in C. This modifier is used with all data types like int , float, double, array, pointer, structure, function

Syntex

extern data_declaration;

Example

extern int a;

17. for  For is a keyword  which is used to repeat looping statements in C Language.

Syntex

for(initialization, Boolean Expresion, increment or dicrement){
// statement(s)
}

Example

output

0 1 2 3 4 5 6 7 8 9

18. goto

goto is a keyword that is used to jumb directly to labled statement when a problem is encountered.

Syntax

goto label_name;
statement(s);
...................
label_name: statements(s)

Example











19. int – int is a keyword in C and it is a data type. int keyword can be signed (Default) or Unsigned types. Default keywords have a range of -32768 to 32767 whole numbers
int a,b,c;
int marks=78;

20. short –  Short is a key word  that is a data type in C. We can use short in following types.

short int ;
un signed short int;
signed short int;

21. long – long is a key word that is a data type in C. We can use long in following types.

long long  int ;
un signed long int;
signed slong int;

22. signed and unsignedSigned keyword is used to store negative or positive values

Syntex.

signed data_diclaration;
unsigned data_diclaration;

Example
signed short int a=32000;
unsigned short int a=32000;

23. returnreturn is a keyword that is used to return the value  and terminate the function

int function_name()
{
int x=10;
return x;
}

24.sizeof The size of is a keyword that evaluates the size of data types

Example

Output

 1
4
4
8

25. registerregister keyword is used to define local variables.

Syntex

register data_declaration;

Example

register int age;

26. static static keyword used for variable declaration and method declaration

Syntex

static data_diclaration;

static function_diclaration;

27. struct – struct is a keyword that is used to create a structure. Structure is a user-defined data type used to store a group of variable in a single record.

The syntax of struct

struct [struct_name]
{
[type1_variable_name];
[type2_variable_name];
………………………………
}

Example

28. typedef –  Typedef is a keyword that is used to give a new symbolic name for the existing name a C Program.

Syntex

typedef struct sturct_name
{
ststement(s)
}Exampletypedef struct student
{
int age;
char name[10];
float avg;
}

29. unionunion means one or more variable used declare a single unit like struct (Structure in C) . Except it allows you to define variables that share  storage space.

Syntex of union keyword

union [union_type_name]
{
data_type diclaration;
}

Example

union student
{
int age;
char name[];
}

30. void – void is a keyword in C Language which is used as a function to return type. Void means that the function can never return a value.

Syntex of void keyword

void function_name(parameter_list)
{
//statement(s)
}

Example for void

void hello(char *name)
{
printf (“hello, %s”,name);
}

31. volatilevolatile is a qualifier that is applied to a variable when it is declared. It means the value of the compiler  variable may changed at any time without any action being taken by the code.

Syntex

syntex of the volatile key word

volatile data_type;
Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.