Identifiers are the names that are given to the various program elements such as functions, variables, union, structure and arrays. It must be unique. They are created to give a unique name to an entity to identify it during the execution time of the program.
There are some rules for constructing identifiers:
int code; int _code;
Both are valid identifiers in C language.
int 0codiens;
It will raise an error, because the C compiler does not allow us to define an identifier which starts from a digit.
int char;
In this case char is a keyword of C language so this is invalid declaration.
int co de;
The given identifier is invalid because the C compiler does not allow us to define an identifier with the white space.
int a=10; int A=10;
Here, a and A are not the same.both are stored in different memory locations.
An identifier can be long, Some implementations of C language recognize only the first 8 characters though most implementations recognize more( around 31 characters).
The ANSI( American national standard institute) suggests we make an identifier with 15 to 20 characters maximum but this is not necessary. Additional characters are carried along for the programmer’s convenience.
Keywords are reserved words of programming languages. The meaning of these words has already been explained to the C compiler. So that’s why we can’t use these words as an identifier or a variable name.
Every word in C program is classified as either a keyword or an identifier or an operator.
A keyword in C is a sequence of characters that the C compiler accepts and recognizes while being used in the program. In C programming, all keywords are in lowercase.
Since lowercase and uppercase characters are not equivalent, We can use an uppercase word as an identifier which is similar to any C keyword.
As we have already mentioned that C has different standards. Each standard has a distinct number of keywords.
int |
float |
signed |
unsigned |
double |
char |
auto |
register |
extern |
static |
if |
else |
switch |
case |
default |
break |
continue |
goto |
return |
void |
const |
volatile |
struct |
union |
enum |
long |
short |
for |
while |
do |
sizeof |
typedef |
The C99 has 37 keywords in it. There are 32 keywords in it which are taken from ANSI C which we have already mentioned in above. The C99 added five more keywords which are _Bool, _Complex, _Imaginary, inline and restrict in ANSI C.In C language, starting with an underscore and a capital letter is not common for keywords in C. That’s why the new words are used through their macros, which keeps the coding style clean.
keyword | Macro | Macro defined in |
---|---|---|
_Bool |
bool |
stdbool.h |
_Complex |
complex |
complex.h |
_Imaginary |
imaginary |
complex.h |
restrict |
- |
- |
inline |
- |
- |
The _Bool keyword is used to declare an integer which is capable of storing 0 and 1.
Syntax of __Bool keyword:
bool <variable name>;
The _Imaginary and _Complex used to declare complex and imaginary which are capable of storing floating point complex numbers.They only work with double, float and long double.
Syntax of __imaginary data type:
double _Imaginary <variable name>; float _Imaginary <variable name>;
Syntax for __Complex data type:
float _Complex <variable name>; long double _Complex <variable name>;
Syntax for restrict pointers:
int *restrict <variable name>; float *restrict <variable name>; void *restrict <variable name>;
keyword | macro | Macro def ined in |
---|---|---|
_Alignas |
alignas |
stdalign.h |
_Alignof |
alignof |
stdalign.h |
_Atomic |
atomic |
stdatomic.h |
_Noreturn |
noreturn |
stdnoreturn.h |
_Generic |
- |
- |
_Thread_local |
- |
- |
_Static_assert |
static_assert |
assert.h |
Note: We will further discuss these data types in detail.