This tutorial provides a brief information on all 32 keywords in C programming.
auto | break | case | char |
const | continue | default | do |
double | else | enum | extern |
float | for | goto | if |
int | long | register | return |
short | signed | sizeof | static |
struct | switch | typedef | union |
unsigned | void | volatile | while |
auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while
The auto keyword declares automatic variables. For example:
This statement suggests that var1 is a variable of storage class auto and type int.
Variables declared within function bodies are automatic by default. They are recreated each time a function is executed.
Since, automatic variables are local to a function, they are also called local variables. To learn more visit C storage class.
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.
Output
1 2 4 5 6
When i is equal to 3, continue statement comes into effect and skips 3. When i is equal to 7, break statement comes into effect and terminates the for loop. To learn more, visit C break and continue statement
The switch and case statement is used when a block of statements has to be executed among many blocks. 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;
}
Visit C switch statement to learn more.
The char keyword declares a character variable. For example:
Here, alphabet is a character type variable.
To learn more, visit C data types.
An identifier can be declared constant by using const keyword.
const int a = 5;
To learn more, visitC variables and constants.
int i;
do
{
print("%d ",i);
i++;
}
while (i<10)
To learn more, visit C do…while loop
Keywords double and float are used for declaring floating type variables. For example:
Here, number is single precision floating type variable whereas, longNumber is a double precision floating type variable.
To learn more, visit C data types.
In C programming, if and else are used to make decisions.
if (i == 1)
printf("i is 1.")
else
prinf("i is not 1.")
If value of i is other than 1, output will be :
i is not 1
To learn more, visit C if…else statement.
Enumeration types are declared in C programming using keyword enum. For example:
Here, a enumerated variable suit is created having tags: hearts, spades, clubs and diamonds.
To learn more, visit [C enum](/c-programming/c-enumeration “C enum”.html).
The extern keyword declares that a variable or a function has external linkage outside of the file it is declared.
To learn more, visit C storage type.
There are three types of loops in C programming. The for loop is written in C programming using keyword for. For example:
for (i=0; i< 9;++i)
{
printf("%d ",i);
}
Output
0 1 2 3 4 5 6 7 8
To learn more, visit C for loop.
The goto keyword is used for unconditional jump to a labeled statement inside a function. For example:
for(i=1; i<5; ++i)
{
if (i==10)
goto error;
}
printf("i is not 10");
error:
printf("Error, count cannot be 10.");
Output
Error, count cannot be 10.
To learn more, visit [C goto](/c-programming/c-goto-statement “C goto”.html).
The int keyword declares integer type variable. For example:
int count;
Here, count is a integer variable.
To learn more, visit C data types.
The short, long, signed and unsigned keywodrs are type modifiers that alters the meaning of a base data type to yield a new type.
short int smallInteger;
long int bigInteger;
signed int normalInteger;
unsigned int positiveInteger;
Data types | Range |
---|---|
short int | -32768 to 32767 |
long int | -2147483648 to 214743648 |
signed int | -32768 to 32767 |
unsigned int | 0 to 65535 |
The return keyword terminates the function and returns the value.
This function func()
returns 5 to the calling function. To learn more, visit C user-defined functions.
The sizeof keyword evaluates the size of data (a variable or a constant).
#include <stdio.h>
int main()
{
printf("%u bytes.",sizeof(char));
}
To learn more, visit C operators.
Output
1 bytes.
The register keyword creates register variables which are much faster than normal variables.
The static keyword creates static variable. The value of the static variables persists until the end of the program. For example:
The struct keyword is used for declaring a structure. A structure can hold variables of different types under a single name.
To learn more, visit C structures.
The typedef keyword is used to explicitly associate a type with an identifier.
A Union is used for grouping different types of variable under a single name.
To learn more, visit [C unions](/c-programming/c-unions “C unions”.html).
The void keyword indicates that a function doesn’t return any value.
Here, function testFunction( )
cannot return a value because the return type is void.
The volatile keyword is used for creating volatile objects. A volatile object can be modified in an unspecified way by the hardware.
const volatile number
Here, number is a volatile object.
Since, number is a constant variable, the program cannot change it. However, hardware can change it since it is a volatile object.
Donloaded from : https://www.programiz.com/c-programming/list-all-keywords-c-language