You are on page 1of 8

C - LANGUAGE PROGRAMMING (programiz) – Part - 1

C Keywords and Identifiers

Character set
A character set is a set of alphabets, letters and some special characters that are valid in C language.
Alphabets
Uppercase: A B C ................................... X Y Z
Lowercase: a b c ...................................... x y z
C accepts both lowercase and uppercase alphabets as variables and functions.
Digits
0123456789

Special Characters in C Programming

, < > . _

( ) ; $ :

% [ ] # ?

' & { } "

^ ! * / |

- \ ~ +  

Special Characters

White space Characters


Blank space, newline, horizontal tab, carriage return and form feed.
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:
int money;
Here, int is a keyword that indicates money is a variable of type int (integer).
As C is a case sensitive language, all keywords must be written in lowercase. Here is a list of all keywords
allowed in ANSI C.

1
C Keywords

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

All these keywords, their syntax, and application will be discussed in their respective topics.
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.
Since automatic variables are local to a function, they are also called local variables.
break and continue
The break statement terminates the innermost loop immediately when it's encountered. It's also used to
terminate the switch statement.
The continue statement skips the statements after it inside the loop for the iteration.
for (i=1;i<=10;++i){
if (i==3)
continue;

2
if (i==7)
break;
printf("%d ",i);
}
Output
12456
When i is equal to 3, the continue statement comes into effect and skips 3. When i is equal to 7, the break
statement comes into effect and terminates the for loop.
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;
Here, alphabet is a character type variable.
const
An identifier can be declared constant by using the const keyword.
const int a = 5;
do...while
int i;
do
{

3
printf("%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;
Here, number is a single-precision floating type variable whereas, longNumber is a double-precision floating
type variable.
if and else
In C programming, if and else are used to make decisions.
if (i == 1)
printf("i is 1.")
else
printf("i is not 1.")
If the value of i is other than 1, the output will be :
i is not 1
enum
Enumeration types are declared in C programming using keyword enum. For example:
enum suit
{
hearts;
spades;
clubs;
diamonds;
};
Here, an enumerated variable suit is created having tags: hearts, spades, clubs, and diamonds.
extern
The extern keyword declares that a variable or a function has external linkage outside of the file it is
declared.
for

4
There are three types of loops in C programming. The for loop is written in C programming using the
keyword for. For example:
for (i=0; i< 9;++i){
printf("%d ",i);
}
Output
012345678
goto
The goto statement is used to transfer control of the program to the specified label. 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 is used to declare integer type variables. For example:
int count;
Here, count is an integer variable.
short, long, signed and unsigned
The short, long, signed and unsigned keywords are type modifiers that alter the meaning of a base data type
to yield a new type.
short int smallInteger;
long int bigInteger;
signed int normalInteger;
unsigned int positiveInteger;

5
Range of int type data types

Data types Range

short int -32768 to 32767

long int -2147483648 to 214743648

signed int -32768 to 32767

unsigned int 0 to 65535

return
The return keyword terminates the function and returns the value.
int func() {
int b = 5;
return b;
}
This function func() returns 5 to the calling function. 
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;
typedef
The typedef keyword is used to explicitly associate a type with an identifier.
typedef float kg;
6
kg bear, tiger;
void
The void keyword meaning nothing or no value.
void testFunction(int a) {
.....
}
Here, the testFunction() function cannot return a value because its 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.
Since number is a constant, the program cannot change it. However, hardware can change it since it is a
volatile object.
union
A union is used for grouping different types of variables under a single name.
union student {
char name[80];
float marks;
int age;
}
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;
static
The static keyword creates a static variable. The value of the static variables persists until the end of the
program. For example:
static int var;
C Identifiers
7
Identifier refers to name given to entities such as variables, functions, structures etc.
Identifiers must be unique. They are created to give a unique name to an entity to identify it during the
execution of the program. For example:
int money;
double accountBalance;
Here, money and accountBalance are identifiers.
Also remember, identifier names must be different from keywords. You cannot use int as an identifier
because int is a keyword.

Rules for naming identifiers


1. A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores.
2. The first letter of an identifier should be either a letter or an underscore.
3. You cannot use keywords like int, while etc. as identifiers.
4. There is no rule on how long an identifier can be. However, you may run into problems in some
compilers if the identifier is longer than 31 characters.
You can choose any name as an identifier if you follow the above rule, however, give meaningful names to
identifiers that make sense. 

You might also like