C Keywords
Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax and they cannot be used as an identifier. For example:
auto | double | int | struct |
break | else | long | switch |
case | enum | register | typedef |
char | extern | return | union |
continue | for | signed | void |
do | if | static | while |
default | goto | sizeof | volatile |
const | float | short | unsigned |
Description of all Keywords in C
auto
The auto keyword declares automatic variables. For example:
auto int var1;
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.
break and continue
The break statement makes the program jump out of the innermost enclosing loop (while, do, for or switch statements) explicitly.
The continue statement skips certain statements inside the loop.
for (i=1;i<=10;++i) { if (i==3) continue; if (i==7) break; printf("%d ",i); }
Output
1 2 4 5 6
switch, case, and default
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; }
char
The char keyword declares a character variable. For example:
char alphabet;
const
An identifier can be declared constant by using the const keyword.
const int a = 5;
do...while
int i; do { print("%d ",i); i++; } while (i<10)
double and float
Keywords double and float are used for declaring floating type variables. For example:
float number; double longNumber;
if and else
In C programming, if and else are used to make decisions.
if (i == 1) printf("i is 1.") else prinf("i is not 1.")
enum
Enumeration types are declared in C programming using keyword enum. For example:
enum suit { hearts; spades; clubs; diamonds; };
for
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
goto
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
int
The int keyword declares integer type variable. For example:
int count;
short, long, signed and unsigned
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;
sizeof
The sizeof keyword evaluates the size of data (a variable or a constant).
#include <stdio.h> int main() { printf("%u bytes.",sizeof(char)); }
Output
1 bytes.
register
The register keyword creates register variables which are much faster than normal variables.
register int var1;
static
The static keyword creates static variable. The value of the static variables persists until the end of the program. For example:
static int var;
struct
The struct keyword is used for declaring a structure. A structure can hold variables of different types under a single name.
struct student{ char name[80]; float marks; int age; }s1, s2;
typedef
The typedef keyword is used to explicitly associate a type with an identifier.
typedef float kg; kg bear, tiger;
union
A Union is used for grouping different types of variable under a single name.
union student { char name[80]; float marks; int age; }
void
The void keyword indicates that a function doesn't return any value.
void testFunction(int a) { ..... }
Here, function
test Function( )
cannot return a value because the return type is void.volatile
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.
0 Comments