Learn C - C Keywords






There are 32 words defined as keywords in the standard ANSI C programming language.

These keywords have predefined uses and cannot be used for any other purpose in a C program.

These keywords are used by the compiler.

KeywordDescription
autoDefines a local variable as having a local lifetime
breakPasses control out of the programming construct
caseBranch control
charBasic data type
constUnmodifiable value
continuePasses control to loop's beginning
defaultBranch control
doDo While loop
doubleFloating-point data type
elseConditional statement
enumDefines a group of constants of type int
externIndicates an identifier as defined elsewhere
floatFloating-point data type
forFor loop
gotoTransfers program control unconditionally
ifConditional statement
intBasic data type
longType modifier
registerStores the declared variable in a CPU register
returnExits the function
shortType modifier
signedType modifier
sizeofReturns expression or type size
staticPreserves variable value after its scope ends
structGroups variables into a single record
switchBranch control
typedefCreates a new type
unionGroups variables that occupy the same storage space
unsignedType modifier
voidEmpty data type
volatileAllows a variable to be changed by a background routine
whileRepeats program execution while the condition is true




Example


#include <stdio.h> 
int main(void) 
{ /*  w  ww . j  av a  2 s .  com*/
   float fRevenue, fCost; 
   fRevenue = 0; 
   fCost = 0; 
   /* profit = revenue - cost */ 
   printf("\nEnter total revenue: "); 
   scanf("%f", &fRevenue); 
   printf("\nEnter total cost: "); 
   scanf("%f", &fCost); 
   printf("\nYour profit is $%.2f\n", fRevenue - fCost); 
   
   return 0;
} 

The code above generates the following result.





Note

using characters as menu choices.


#include <stdio.h>  
int main(void) 
{ /*  w  ww . j av a 2  s  . c o m*/
   char cResponse = '\0'; 
   printf("\n\tAC Control Unit\n"); 
   printf("\na\tTurn the AC on\n"); 
   printf("b\tTurn the AC off\n"); 
   printf("\nEnter your selection: "); 
   scanf("%c", &cResponse); 
   if (cResponse == 'a') 
      printf("\nAC is now on\n"); 
   if (cResponse == 'b') 
      printf("\nAC is now off\n"); 
    
   return 0;
} 

The code above generates the following result.