Sunday 1 July 2012

charset identifier and keyword


C Programming Keywords and Identifiers:

Character set:

Character set are the 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

Digits:
0 1 2 3 4 5 6  8 9


Special Characters:     

Special Characters in C language
 



+  -  * /  = % & # ! ? ^ ” ‘ /  | < > ( ) [  ]  {  } : ; . , ~ @ ! \

The white spaces used in C programs are: blank space, horizontal tab, carriage return, new line and form feed.






































Identifiers and Keywords:

Identifiers

In C programming, identifiers are names given to C entities, such as variables, functions, structures etc. Identifier are created to give unique name to C entities to identify it during the execution of program. For example:

int money;
int mango_tree;

Here, money is a identifier which denotes a variable of type integer. Similarly, mango_tree is another identifier, which denotes another variable of type integer.

Rules for writing identifier
  1. An identifier can be composed of letters (both uppercase and lowercase letters), digits and underscore '_' only.
  2. The first letter of identifier should be either a letter or an underscore. But, it is discouraged to start an identifier name with an underscore though it is legal. It is because, identifier that starts with underscore can conflict with system names. In such cases, compiler will complain about it. Some system names that start with underscore are _fileno, _iob, _wfopen etc.
  3. There is no rule for the length of an identifier. However, the first 31 characters of an identifier are discriminated by the compiler. So, the first 31 letters of two identifiers in a program should be different.
Tips for Good Programming Practice :
Programmer can choose the name of identifier whatever they want. However, if the programmer choose meaningful name for an identifier, it will be easy to understand and work on, particularly in case of large program.


Identifiers are names given to various program elements such as variables, functions, and arrays. Identifiers consist of letters and digits, in any order, except that the first character must be a letter. Both uppercase and lowercase letters are permitted and the underscore may also be used, as it is also regarded as a letter. Uppercase and lowercase letters are not equivalent, thus not interchangeable. This is why it is said that C is case sensitive. An identifier can be arbitrarily long.
The same identifier may denote different entities in the same program, for example, a variable and an array may be denoted by the same identifier, example below.

int sum, average, A[10]; // sum, average and the array name A are all identifiers.

The _ _func_ _ predefined identifier:-

The predefined identifier __func__ makes a function name available for use within the function. Immediately following the opening brace of each function definition, _ _func_ _ is implicitly declared by the compiler in the following way:


static const char _ _func_ _[] = "function-name";

where function-name is the name of the function.
consider the following example
 
 
#include <stdio.h>
void func1(void)    {
         printf("%s\n",__func__);
         return;
}
int main() {
     myfunc();
}
The output would be
func1

Keywords

Keywords are reserved words that have standard predefined meanings. These keywords can only be used for their intended purpose; they cannot be used as programmer defined identifiers. Examples of some keywords are: int, main, void, if.

 

Keywords in C Language:

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

 

 

No comments:

Post a Comment