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.
Keyword | Description |
---|---|
auto | Defines a local variable as having a local lifetime |
break | Passes control out of the programming construct |
case | Branch control |
char | Basic data type |
const | Unmodifiable value |
continue | Passes control to loop's beginning |
default | Branch control |
do | Do While loop |
double | Floating-point data type |
else | Conditional statement |
enum | Defines a group of constants of type int |
extern | Indicates an identifier as defined elsewhere |
float | Floating-point data type |
for | For loop |
goto | Transfers program control unconditionally |
if | Conditional statement |
int | Basic data type |
long | Type modifier |
register | Stores the declared variable in a CPU register |
return | Exits the function |
short | Type modifier |
signed | Type modifier |
sizeof | Returns expression or type size |
static | Preserves variable value after its scope ends |
struct | Groups variables into a single record |
switch | Branch control |
typedef | Creates a new type |
union | Groups variables that occupy the same storage space |
unsigned | Type modifier |
void | Empty data type |
volatile | Allows a variable to be changed by a background routine |
while | Repeats program execution while the condition is true |
#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.
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.